eddic / fastcgipp

fastcgi++: A C++ FastCGI and Web development platform:
https://fastcgipp.isatec.ca
GNU Lesser General Public License v3.0
312 stars 95 forks source link

undefined reference to pthread, for examples #110

Open cantbothertoshave opened 2 years ago

cantbothertoshave commented 2 years ago

I am trying to cross-compile this for arm-linux-gnueabihf (raspberry pi), so I created a toolchain file setting compilers, assembler, linker etc to those prefixed toolchain binaries.

The library builds.

When I try "make timer.fcgi" (or other examples), it gives me a linker error: undefined reference to 'pthread_cond_clockwait' and 'pthread_create'.

Now I know pthread-related linker errors when quickly setting up an own little project and just add an option to statically link that. But this shouldn't happen here, right? Is there a conceivable way of how that can happen due to the cross-compilation setup missing something? I'm not exactly experienced in CMake.

cantbothertoshave commented 2 years ago

Ok, feeling like a monkey poking an ant hill with a stick, I found, in CMakeLists.txt the loop where it goes through the examples, i.e. line 213: target_link_libraries(${EXAMPLE}.fcgi PRIVATE Fastcgipp::fastcgipp pthread) --- I added that "pthread", and then it all builds. But for timer.fcgi, there are a bunch of warnings relating to std containers, something about "parameter passing changed in GCC 7.1" and such. I was using GCC 10.2 (cross compiler for arm-linux-gnueabihf, running on Debian11 in a VirtualBox VM on an Intel i7 laptop)

Erroneous1 commented 2 years ago

Make sure your cmake project is doing find_package(Fastcgipp) and that you're calling target_link_libraries(targetname PRIVATE Fastcgipp::fastcgipp) (could be public if needed). Fastcgi++ requires C++20 and the Threads cmake target which should be automatically linked to your target if you link to the Fastcgipp::fastcgipp target.

If you need to manually set your flags you'll want to add -std=c++20 and -lpthread for linux systems on GCC and Clang.

rockingdice commented 1 year ago

Make sure your cmake project is doing find_package(Fastcgipp) and that you're calling target_link_libraries(targetname PRIVATE Fastcgipp::fastcgipp) (could be public if needed). Fastcgi++ requires C++20 and the Threads cmake target which should be automatically linked to your target if you link to the Fastcgipp::fastcgipp target.

If you need to manually set your flags you'll want to add -std=c++20 and -lpthread for linux systems on GCC and Clang.

this DEFINITELY should be in the README file! @eddic