Solaris 10下实现SIGEV_THREAD编译报错求助:未定义符号问题
Hey there! Let's work through this linking error you're facing on Solaris 10 while trying to add SIGEV_THREAD support to your task scheduler. Those "undefined first referenced symbol" errors mean the linker can't find the actual implementations for those __timer_* functions your code is calling. Here are the most likely fixes to try:
1. Make sure you're compiling all required source files
You mentioned downloading timer_create.c and other supporting files, but your compile command only includes *.cpp files. If those missing __timer_* symbols are defined in .c files (like the timer_create.c you got), the linker has no way to find them unless you include those files in the build.
Update your command to include both .cpp and .c files:
g++ -I./ -std=c++11 -o sol10 *.cpp *.c
Or if you want to be explicit about specific files (to avoid compiling unrelated ones):
g++ -I./ -std=c++11 -o sol10 your_main.cpp timer_create.c other_support_files.c
2. Link against the pthread library
Solaris requires explicit linking against the pthread library when working with thread-related functionality. Add the -lpthread flag to your command (note: it should come after your source files, as the linker processes dependencies in order):
g++ -I./ -std=c++11 -o sol10 *.cpp *.c -lpthread
3. Verify your downloaded files include all function definitions
Double-check the timer_create.c and other files you grabbed—make sure they actually contain implementations for the missing symbols like __timer_mutex, _Z20__timer_thread_startP11thread_node, and so on. If any of these functions are missing, you probably didn't download the full set of supporting files from your source, so you'll need to retrieve the complete package.
4. Add Solaris-specific POSIX compatibility flags
Solaris's GCC may need additional macros to enable POSIX extension features that your timer implementation relies on. Try adding -D_POSIX_C_SOURCE=200112L or -D__EXTENSIONS__ to your compile command:
g++ -I./ -std=c++11 -D_POSIX_C_SOURCE=200112L -o sol10 *.cpp *.c -lpthread
Start with steps 1 and 2 first—those are the most common causes of this exact type of linking error on Solaris 10. If those don't fix it, move on to verifying your source files and adding compatibility flags.
内容的提问来源于stack exchange,提问作者Shivam

