0

I have a given project structure

.
├── CMakeLists.txt
├── lib
│   └── pixel_reader
│       ├── CMakeLists.txt
│       └── src
│           ├── pixel_reader.cpp
│           ├── pixel_reader.h
│           ├── lodepng.cpp
│           └── lodepng.h
├── main.cpp

With the following CMakeLists

./CMakeLists.txt

cmake_minimum_required(VERSION 3.17)
project(pov_system VERSION 1.0)

add_subdirectory(lib/pixel_reader)

add_executable(pov_system main.cpp)

target_link_libraries(pov_system PRIVATE pixel_reader)

./pixel_reader/CMakeLists.txt

add_library(
    pixel_reader SHARED
    src/pixel_reader.cpp
    src/pixel_reader.h
    src/lodepng.cpp
    src/lodepng.h
)

target_include_directories(pixel_reader PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")

While building this CMake Project, I get the following error.

[build] 
[build]   pixel_reader.cpp
[build]   pixel_reader.vcxproj -> C:\Programming\GitHub\pov_system\build\lib\pixel_reader\Debug\pixel_reader.dll
[build]   main.cpp
[build] LINK : fatal error LNK1104: Datei "lib\pixel_reader\Debug\pixel_reader.lib" kann nicht geöffnet werden. [C:\Programming\GitHub\pov_system\build\pov_system.vcxproj]
[build] Der Build wurde mit dem Exitcode 1 abgeschlossen.

Question

Am I adding and linking the library correctly? What sources do I have to add as parameter to add_library? I have the feeling that this is my problem.

If you need additional informatons, please let me know.

  • 1
    You need to **export** at least one **symbol** from your library, otherwise linking with it has no sense and export file is not created. See more in the duplicate question. – Tsyvarev Jul 13 '20 at 20:04
  • 1
    Side note: When posting error messages, it's better if they're in English. I'm not sure how to do this from within VS (which you seem to be using?) but on the commandline on Linux just add `LANG=` in front of the cmake (or any, really) command. – Daniel Jour Jul 13 '20 at 20:05
  • Have a look at: https://stackoverflow.com/a/40743080/260313. It looks you're only building a DLL but then you try to link against a LIB. – rturrado Jul 13 '20 at 20:12
  • [https://stackoverflow.com/a/40743080/487892](https://stackoverflow.com/a/40743080/487892) is a good answer. I recommend you study this even if you are not using Qt. – drescherjm Jul 13 '20 at 20:21

0 Answers0