# cmake does not create rules to create .lib target.

**URL:** https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211
**Category:** Usage
**Created:** [December 16, 2024, 10:23pm UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211 "2024-12-16T22:23:08Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Marco\_Antoniotti](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@Marco\_Antoniotti](https://discourse.cmake.org/u/Marco_Antoniotti)
#### Post date: [December 16, 2024, 10:23pm UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211/1 "2024-12-16T22:23:08Z")

</div>

Hi

I have a build that is very simple and essentially creates a shared library (an Emacs module).

The subdirectory CMakeLists.txt file just contains the following. The top CMakeLists.txt just contains, essentially, the definition of EMACS\_MODULE\_INCLUDE\_DIR.

add\_library(platel\_emacs\_module SHARED platel\_emacs\_module.c platel.c)

set\_target\_properties(platel\_emacs\_module PROPERTIES PREFIX “”)

target\_include\_directories(platel\_emacs\_module  
INTERFACE  
${CMAKE\_CURRENT\_SOURCE\_DIR}  
)

target\_include\_directories(platel\_emacs\_module  
PUBLIC  
“${EMACS\_MODULE\_INCLUDE\_DIR}”  
)

On Mac OS things work as advertised (following Steps 1-3 of the Tutorial). But on Windows with VS I get this error. Yes, the VS environment is set up properly. It appears that cmake creates a spurious target for which no build instructions are given; this seems to be for “testing”.

C:\Users\marco\Projects\Lang\ELisp\platel\platel\_build\>cmake --build .  
MSBuild version 17.12.12+1cce77968 for .NET Framework

1\>Checking Build System  
Building Custom Rule C:/Users/marco/Projects/Lang/ELisp/platel/c/CMakeLists.txt  
platel\_emacs\_module.c  
platel.c  
Generating Code…  
platel\_emacs\_module.vcxproj → C:\Users\marco\Projects\Lang\ELisp\platel\platel\_build\c\Debug\platel\_emacs\_module.dll  
Building Custom Rule C:/Users/marco/Projects/Lang/ELisp/platel/CMakeLists.txt  
platel\_test.c  
**LINK : fatal error LNK1104: cannot open file ‘c\Debug\platel\_emacs\_module.lib’ [C:\Users\marco\Projects\Lang\ELisp\plat\*\*\*\*el\platel\_build\platel\_check.vcxproj]**

C:\Users\marco\Projects\Lang\ELisp\platel\platel\_build\>

Any ideas about what could be done to fix this?

Thanks

Marco

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [December 17, 2024, 7:34am UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211/2 "2024-12-17T07:34:54Z")

</div>

Does your DLL actually export any symbols? An import `.lib` is only created if any symbols are exported from the DLL.

---

<div class="post-metadata">

### Author: ![marcoxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marcoxa/32/5200_2.png) [@marcoxa](https://discourse.cmake.org/u/marcoxa)
#### Post date: [December 17, 2024, 2:45pm UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211/3 "2024-12-17T14:45:49Z")

</div>

AFAIU no. I do not “export” any symbols.

The question is that cmake seems to create a target, without analyzing the spec (I do not pretend it analyzed the code), but it does so without any warning.

What am I after? A single spec that generated makefiles in a platform dependent way, and AFAIU, the Tutorials do not work on Windows.

MA

---

<div class="post-metadata">

### Author: ![bill.hoffman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bill.hoffman/32/13_2.png) [@bill.hoffman](https://discourse.cmake.org/u/bill.hoffman)
#### Post date: [December 17, 2024, 10:33pm UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211/4 "2024-12-17T22:33:36Z")

</div>

See this blog: [https://www.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/](https://www.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/). For C++ on Windows, you need to export symbols or you don’t get an import library.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [December 18, 2024, 6:09am UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211/5 "2024-12-18T06:09:14Z")

</div>

Does it help if you use MODULE instead of SHARED for add\_library()?

---

<div class="post-metadata">

### Author: ![marcoxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marcoxa/32/5200_2.png) [@marcoxa](https://discourse.cmake.org/u/marcoxa)
#### Post date: [December 19, 2024, 4:07pm UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211/6 "2024-12-19T16:07:41Z")

</div>

Thank you. That helps. However, no mention of it (I may be wrong) is made in the Tutorial. Hence, if you try the tutorial on a Windows machine with VS installed (no other UN\*X-like stuff), you are going to get stumped.

Let me do some more tests…

All the best

Marco

---

<div class="post-metadata">

### Author: ![marcoxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marcoxa/32/5200_2.png) [@marcoxa](https://discourse.cmake.org/u/marcoxa)
#### Post date: [December 19, 2024, 4:10pm UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211/7 "2024-12-19T16:10:12Z")

</div>

Thanks. Yes, but that is not the problem.

The problem is that the tutorial assumes a UN\*X setup and Windows DLLs cannot be simply built.  
Plus IMHO the MSVC build system generator is somewhat broken; it appears to create a project file which contains a broken .lib dependency: it should know better IMHO.

MA

---

<div class="post-metadata">

### Author: ![bill.hoffman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bill.hoffman/32/13_2.png) [@bill.hoffman](https://discourse.cmake.org/u/bill.hoffman)
#### Post date: [December 19, 2024, 4:56pm UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211/8 "2024-12-19T16:56:13Z")

</div>

Exactly where in the Tutorial? The Tutorial code is tested on all platforms.

---

<div class="post-metadata">

### Author: ![marcoxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marcoxa/32/5200_2.png) [@marcoxa](https://discourse.cmake.org/u/marcoxa)
#### Post date: [December 21, 2024, 6:30pm UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211/9 "2024-12-21T18:30:42Z")

</div>

Hi Bill

I think I reconstructed my personal issue with the Tutorial. Actually there are two. The first one is that, unlike my wife, I read a bit and then I try things; she reads everything beforehand.

Apart from that, I followed the tutorial and tried to build a `SHARED` library. Alas, the Tutorial (Step 2) does not build a `SHARED` library, but just links in an object, static, one.

Here is the catch: if you add `SHARED` to Step 2, TODO 1, the compilation on UN\*X works just fine, with the `.so` or the `.dylib` appearing in the proper folder, but on Windows, MSBuild fails with the error reported before (in an empty `Step2_build` folder; if you built the object file before and then just add `SHARED` to the `MathFunctions/CMakeLists.txt` `add_library`, the build would succeed (obviously)).

How to fix it? Add a note saying that to build `SHARED` libraries, especially on Windows, you need to RTMF about `target_link_libraries`. As it is now, you can run the tutorial Step 2 without problems on UN\*X, but you need to add things on Windows.

Yes. A note in the Tutorial would suffice.

Nope. I have not yet figured out how to fix the issue.

All the best

MA

---

<div class="post-metadata">

### Author: ![marcoxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marcoxa/32/5200_2.png) [@marcoxa](https://discourse.cmake.org/u/marcoxa)
#### Post date: [December 22, 2024, 10:44am UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211/10 "2024-12-22T10:44:32Z")

</div>

Progress report:

I added

`set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS True)`

in the top `CMakeLists.txt` file.

Invoking `cmake --build .` now works, but the executable cannot found the `.dll` (which is, in fact, nowhere to be found in the `PROJECT_SOURCE_DIR` or `PROJECT_BINARY_DIR`.

I guess I have to do some “installation” before moving on, don’t I?

All the best and Happy Holidays

Marco

---

<div class="post-metadata">

### Author: ![bill.hoffman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bill.hoffman/32/13_2.png) [@bill.hoffman](https://discourse.cmake.org/u/bill.hoffman)
#### Post date: [December 31, 2024, 3:05pm UTC](https://discourse.cmake.org/t/cmake-does-not-create-rules-to-create-lib-target/13211/11 "2024-12-31T15:05:43Z")

</div>

In this section shared exports are covered in the tutorial: [https://cmake.org/cmake/help/latest/guide/tutorial/Selecting%20Static%20or%20Shared%20Libraries.html](https://cmake.org/cmake/help/latest/guide/tutorial/Selecting%20Static%20or%20Shared%20Libraries.html)
