2

I am new to CMake and having trouble understanding how to use it.

I have a cross-platform c++ project. It builds using CMake and my CMakeLists.txt lives in a folder called MyProject along with the project. I checked out a pugixml git submodule and it now lives under MyProject/pugixml, with its sources being under MyProject/pugixml/src. It however has its own CMake file: MyProject/pugixml/CMakeLists.txt.

How do I modify my CMakeLists.txt to also build and use pugixml? I tried something like

include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${GENERATED_HEADER_OUTPUT_DIRECTORY} pugixml/src)

and

add_library(PugiXML deps/pugixml/src/pugiconfig.hpp deps/pugixml/src/pugixml.cpp deps/pugixml/src/pugixml.hpp)

and

add_subdirectory(pugixml) in different combinations (these are examples I found on Github), but it doesn't work - I get unresolved external symbol errors, so I assume the cpp never got compiled.

2
  • 2
    I get "unresolved external symbol" errors - This means you need to link with a library. add_subdirectory(pugixml) just builds external library, but linking with it should be performed explicitely with target_link_libraries. Commented Jan 12, 2018 at 7:43
  • Also, consider using the more modern target_include_directories instead of the old include_directories. Commented Jan 12, 2018 at 8:05

1 Answer 1

0

Try this:

add_subdirectory(pugixml)
target_link_libraries(MyProject PugiXML)

assuming PugiXML is the target name that is exposed by the CMake files in /pugixml.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.