Skip to content
Advertisement

Cannot get mixed C and Ada program to link with pthread library

I am writing a program in C. I am getting the error:

file_name.c:(.text+0x5d): undefined reference to `pthread_create'

This specific error comes up when gcc is linking my file_name.o with my main ADA file.

For the actual compilation of the C file, I have tried using both:

gcc -c -pthread file_name.c 

as well as:

gcc -c file_name.c -lpthread

Neither of these seem to work. Any thoughts?

UPDATE: One thing I did not realize is that when combining C and ADA, the C libraries are included when using gnatmake.

The problem was solved by using:

 gnatmake ada_file.adb -o -largs c_file.o -lpthread

Advertisement

Answer

If you are using -c switch, you are not linking your code. You are simply compiling it into object files. There’s no point in specifying the libraries at this stage. Your -l parameter is simply ignored – it has no effect and no meaningful purpose when -c is present.

The libraries are supposed to be supplied at the moment of linking, i.e. at the moment when you combine your object files into the final executable (without -c, of course). You are not showing us that command line. That linking line is exactly where you have to add your -lpthread parameter.

Advertisement