![]() ![]() This only happens for static library compilation due to how CMake interprets it. What is happening here is that CMake links the libPocoXML.a, looks for the function in subsequent libraries that are linked and finds nothing. Reversing the order allows libPocoXML.a to find the desired function later on in libPocoFoundation.a. One example here is the Poco::UTF8Encoding::UTF8Encoding() function. This is because when CMake links the libPocoXML.a library, it makes a note of the external functions that are called and looks for them to be linked in the subsequent libraries. Reversing the order of linking the libraries helps. It seems that the libPocoXML.a static library is trying to call functions in libPocoFoundation.a but can’t find them. usr/local/lib/libPocoXML.a(XMLWriter.o): In function `Poco::XML::XMLWriter::XMLWriter(std::ostream&, int)':XMLWriter.cpp:(.text+0x28b3): undefined reference to `Poco::UTF8Encoding::UTF8Encoding()'XMLWriter.cpp:(.text+0x28cc): undefined reference to `Poco::UTF8Encoding::UTF8Encoding()' ![]() Order of Static Linking Mattersĭoing link_libraries(libPocoFoundation.a) Tells CMake to look for this static library file in the linked directories, and build it statically into your binary. It is interpreted as a dynamic linked library. In your CMakeLists.txt file, first make sure you link the directory to find your files: link_directories("/usr/local/lib")ĬMake has a magic link_libraries() function which takes in the library specified and determines how you want it to be compiled (statically or dynamically linked). I use CLion, which (currently) enforces the use of CMake in compiling C/C++ projects. You don’t have to copy the libraries that you use manually to the target system CMake link_libraries() Magic This allows for ease of deployment, at the expense of a larger binary executable. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |