1

With g++ I compile my program "g++ main.cpp -lpq" without error, and with cmake on Clion this error appears

i using #include <'postgresql/libpq-fe.h'>

>/opt/clion-2018.3.4/bin/cmake/linux/bin/cmake --build /home/dev/Bureau/ENEDIS/PGsql/cmake-build-debug --target PGsql -- -j 2 [ 50%] Linking CXX executable PGsql CMakeFiles/PGsql.dir/main.cpp.o : Dans la fonction « CloseConn(pg_conn*) » : /home/dev/Bureau/ENEDIS/PGsql/main.cpp:9 : référence indéfinie vers « PQfinish » CMakeFiles/PGsql.dir/main.cpp.o : Dans la fonction « ConnectDB() » : /home/dev/Bureau/ENEDIS/PGsql/main.cpp:19 : référence indéfinie vers « PQconnectdb » /home/dev/Bureau/ENEDIS/PGsql/main.cpp:22 : référence indéfinie vers « PQstatus » CMakeFiles/PGsql.dir/main.cpp.o : Dans la fonction « CreateEmployeeTable(pg_conn*) » : /home/dev/Bureau/ENEDIS/PGsql/main.cpp:175 : référence indéfinie vers « PQresultStatus » /home/dev/Bureau/ENEDIS/PGsql/main.cpp:178 : référence indéfinie vers « PQclear » /home/dev/Bureau/ENEDIS/PGsql/main.cpp:185 : référence indéfinie vers « PQclear » collect2: error: ld returned 1 exit status CMakeFiles/PGsql.dir/build.make:83: recipe for target 'PGsql' failed make[3]: *** [PGsql] Error 1 CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/PGsql.dir/all' failed make[2]: *** [CMakeFiles/PGsql.dir/all] Error 2 CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/PGsql.dir/rule' failed make[1]: *** [CMakeFiles/PGsql.dir/rule] Error 2 Makefile:118: recipe for target 'PGsql' failed make: *** [PGsql] Error 2 

My CMakeList.txt

cmake_minimum_required(VERSION 3.13) project(PGsql) set(CMAKE_CXX_STANDARD 17) add_executable(PGsql main.cpp) 

I guess a configuration is missing in CMAKE but I do not know what

0

1 Answer 1

2

You didn't make CMake pass -lpq. Use target_link_libraries() for that:

target_link_libraries(PGsql pq) 

Note that to make your program portable, you first need to find libraries and includes you are going to use. See find_package(), find_library() and find_path() commands.

You could've also bothered translating error messages to English.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.