Reputation: 11
After building the code when run the executable I get error
./test_pq: error while loading shared libraries: libpqxx-6.2.so: cannot open shared object file: No such file or directory
Example of my CMake file:
cmake_minimum_required(VERSION 3.24)
set(CMAKE_CXX_STANDARD 17)
find_library(pqxx libpqxx.so PATHS "/opt/bb/lib64")
find_library(pq libpq.so PATHS "/opt/bb/lib64")
if(EXISTS ${pqxx})
message(STATUS "found Path ${pqxx}")
endif()
add_executable(test_pq test_pq.cpp)
target_include_directories(test_pq
PUBLIC
"/opt/bb/include/pqxx6"
)
target_compile_options(test_pqa
PUBLIC
-std=c++17
-pthread
)
target_link_options(test_pq
PUBLIC
-L/opt/bb/lib64
)
target_link_libraries(test_pq
PUBLIC
pqxx
pq
)
C++ code:
#include <string>
#include <iostream>
#include <pqxx/pqxx>
int main(int argc, char ** argv)
{
try
{
pqxx::connection connectionObject("host=test port=10991 dbname=test user=test password=test");
pqxx::work worker(connectionObject);
if (connectionObject.is_open()) {
std::cout << "Opened database successfully: " << connectionObject.dbname() << "\n";
try {
pqxx::result response = worker.exec("select * from employee");
std::cout << response.size() << "\n";
for (int i = 0; i < response.size(); i++) {
std::cout << "ID: " << response[i][0].c_str() << " Name: " << response[i][2].c_str() << "\n";
}
}
catch (const std::exception& e) {
std::cout << e.what() << "\n";
}
}
else {
std::cout << "Can't open database" << "\n";
return 1;
}
// C.disconnect();
}
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}
I am ding simple cmake ..
and make VERBOSE=1
. Its building and Linking and all looks good:
/opt/rh/devtoolset-12/root/usr/bin/c++ -L/opt/bb/lib64 CMakeFiles/ball_init.dir/ball_init.cpp.o -o ball_init -lpqxx -lpq
Not sure what am I missing here.
Upvotes: 0
Views: 112