Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It seems that it's not linking to the library, but when i add

target_link_libraries(main /usr/include/libmodbus.so)

to the CMakeList.txt and try to compile i get:

(target_link_libraries):
   Cannot specify link libraries for target "main" which is not built by this project.

And that is because main is not a target that you define in your CMakeLists.txt.

You can only link libraries against things for which you have a add_executable(..) or a add_library(..) statement. In your case, that would be converter, tfTest and scaraListen.

From the error message you posted, it would appear that the main function you posted is in a file called scaraListen.cpp, so I'm guessing you should add the libmodbus.so library to the target_link_libraries(scaraListen ..) statement.

PS: as I wrote in my comment, you might want to avoid hard-coding absolute paths to headers and libraries in your CMakeLists.txt.

It seems that it's not linking to the library, but when i add

target_link_libraries(main /usr/include/libmodbus.so)

to the CMakeList.txt and try to compile i get:

(target_link_libraries):
   Cannot specify link libraries for target "main" which is not built by this project.

And that is because main is not a target that you define in your CMakeLists.txt.

You can only link libraries against things for which you have a add_executable(..) or a add_library(..) statement. In your case, that would be converter, tfTest and scaraListen.

From the error message you posted, it would appear that the main function you posted is in a file called scaraListen.cpp, so I'm guessing you should add the libmodbus.so library to the target_link_libraries(scaraListen ..) statement.statement (which is similar to what @sonyccd posted).

PS: as I wrote in my comment, you might want to avoid hard-coding absolute paths to headers and libraries in your CMakeLists.txt.