I started with C and C++ a few days ago and I'm losing my mind with this problem. I wrote and compiled a program in C++ using cmake in a Windows Subsystem for Linux (WSL, Ubuntu). The program opens a CSV file, does some filtering and streams out the result as a JSON string. I need to process very fast some csv files in my website, which is hosted by Bluehost, so I thought I could make something in C++ and run it from php with the exec()
function. The server uses Linux and php for the backend.
Before going deeper into C++ I compiled a simple program that prints "Hello world!" using
printf()
and tested it withexec()
in the server. It worked fine.Then I spent some time on C++ and got an executable that works perfectly when I run it in my own device (WSL).
Finally I upload to the server the executable and all the libraries (listed with
ldd
), exceptlinux-vdso.so.1
, and try to run the program. All the files are in the same directory since I can't access the libs of the server. It throws the following error:
./lib/esp_query: relocation error: /lib/libpthread.so.0: symbol __tunable_get_val, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference"
Both libpthread.so.0
and ld-linux-x86-64.so.2
are libraries that the command ldd
listed and I uploaded to the server. Before that, I tried to run a simple "Hello world!" example with printf
in the server and it worked fine, so I know I can run this kind of files in the server and the c++ code isn't the problem since it worked fine in my device.
I think there's a problem with the libraries, but I'm unable to find where the problem is and a way to fix it. This is the CMakeLists.txt:
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH $ORIGIN)
cmake_minimum_required(VERSION 3.16)
project(esp_query)
set(CMAKE_CXX_STANDARD 17)
find_package(DataFrame REQUIRED CONFIG)
add_executable(esp_query esp_query.cc)
target_link_libraries(esp_query PRIVATE DataFrame Threads::Threads)
target_compile_options(esp_query
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/bigobj>
)
I've been a couple of days looking for a fix, but I didn't find anything like that in Google or in other similar questions in this site. Can you help me point out where's the error and how can I fix it, please?
EDIT: solved. The problem was a bit more complex, but the solution was the same that fabian and Someprogrammerdude pointed in their comments and I think this make be helpful for somebody in the future.
- I downloaded and installed a CentOS 7 linux distro in order to make the compilation in an OS with similar libraries (since the web server uses Cloudlinux 6.10 and both Cloudlinux 6.10 and CentOS 6 gave me weird errors when trying to install).
- I was using the C++ DataFrame package by hosseinmoein. This package requires C++ 11 standards that are not supported by the Cent OS 7 and gcc/g++ base libraries (given the version of the compiler avalaible at yum). I guess that it is very unlikely that the admins of Bluehost web servers installed a newer version of the compiler, so I wanted to keep it in that version too, to avoid more problems. This forced me to discard the DataFrame package option and make another program that complies with C++ 98 standards. This worked like a charm.