How do I link expat into a project
cmake, linux, ubuntu
Solution
If you don't need the very latest expat version, you should be able to use `sudo apt-get install expat`.
If you want the most recent version, download the source and extract it. Then:
cd <expat root>
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr (default install path is /usr/local)
make
sudo make install
Once it's installed, you can find it using CMake's `FindEXPAT` module.
So for example,
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(MyTest)
include(FindEXPAT)
find_package(EXPAT REQUIRED)
include_directories(${EXPAT_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} <list of your source files>)
target_link_libraries(${PROJECT_NAME} ${EXPAT_LIBRARIES})
Problem
I have project that depends on expat. My problem is that I cannot link to expat. I use Ubuntu (debian environment) and need to use cmake to build a makefile. I´ve tried to download the source and link to it inside my CMakeLists.txt: ``` include_directories( ... ${CMAKE_SOURCE_DIR}/expat-2.1.0/lib ... ) ``` I have tried to move the .c-files and link to them individually: ``` add_executable(${PROJECT_NAME} ... src/xmlrole.c src/xmltok.c src/xmltok_impl.c src/xmltok_ns.c src/xmlparse.c ... ) ``` Though this doesn´t work and get, when linking, error in xmlparse.c Does somebody know how you properly link a library inside a CMakeLists.txt file? Is it necessary to download the source code and link to the file themselves (which I can´t get working)? Is downloading the source necessary or is it possible to link to the ".so - file" that is created when running "sudo apt-get install expat"?