My cmake script successfully built executable file, but gave segmentation fault at run.
Can anybody point me what should I fix ? The command line above built and ran normally, and if I linked libpthtread.so by my cmake script it also terminated without issue.
main.c
#include <pthread.h> #include <stdio.h>
void work(void parg){
int val = (int)parg;
printf(“worker tid=%d\n”, *val);
*val = 100;
}
You should not be manually creating imported static libraries for system libraries! The correct commands are find_library or (better) find_package. In this case, the FindThreads module is what you need.
Also, for installing, prefer to use the GNUInstallDirs module.
I noticed the suggested method, which uses include(GNUInstallDirs), by alex is the best way to make a packge by cpack. My script created .deb and .rpm package with absolute pass. This is going to be trouble when you install to your system. However, the proposed method generate packages with relocatable path.