简体   繁体   中英

Error while linking libconfig with c++ using cmake?

Here is the cmake file that i am using

cmake_minimum_required (VERSION 3.0)
project (midasd)

set (midas VERSION_MAJOR 0)
set (midas VERSION_MINOR 0)
set (midas VERSION_REVISION 1)

find_library(libconfig libconfig)

add_executable(midasd src/main.cpp)

target_link_libraries(midasd "${libconfig_LIBS}")

The problem i am facing is undefined reference for config_init . The main function is as follows

#include <libconfig.h>

int main(int argc, char *argv[])
{
        midas::midasCtx *container = new midas::midasCtx(argc,argv);
        config_t cfg;
        config_init(&cfg);
        return 0;
}

Where am i going wrong with CMAKE ?

Actually the libconfig is recognized as simply -lconfig not -llibconfig in linking argument. The CMakeLists.txt should contain

target_link_libraries(my_project config)

Source

This manual( https://hyperrealm.github.io/libconfig/libconfig_manual.html ) says " To link with the library, specify '-lconfig++' as an argument to the linker. "

So I fixed like following code and build was completed.

target_link_libraries(my_project config++)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM