Cmake nested library

We have a C/C++ project organized as follows:

 lib1/ CMakeLists.txt sublib1/ CMakeLists.txt foo.c log.c log.h 

The sublib1/ directory is associated with the CMake add_library and target_link_libraries in the CMakeLists.txt file.

Change: We cannot call from foo.c/some-func function from log.c/some-func-2 . Linker complains that these functions are undefined.

+4
source share
1 answer

The order that libraries and object files appear in your link matters and can cause problems with undefined characters. You do not give much information about your post, but try to tell the linker to consider all your libraries as a group. How in:

 --start-group <all your libs> --end-group 

From the linker documentation:

Typically, an archive is executed only once in the order in which it is specified on the command line. If the symbol in this archive is necessary to resolve the undefined symbol, which is indicated by the object in the archive, which appears later on the command line, the linker will not be able to resolve this link. Having grouped the archives, they will all be searched until all possible links are resolved. Using this option has significant performance. It is best to use it only when there are unavoidable circular references between two or more archives.

+1
source

Source: https://habr.com/ru/post/1379648/


All Articles