GNU make 4.1 does not load libpthread

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

GNU make 4.1 does not load libpthread

彭怀敏
Hi, I am using Ubuntu16.04, with GNU make 4.1.
I was failed while built my project which referenced to libpthread and libm, but it was OK while used Ubuntu10.04 with GNU make 3.81.
I found the difference of the "strace make" output between the two versions of make, that LD will open libpthread after open libc in v3.81, but it will not open libpthread in v4.1, and thus I got a lot of "undefined reference to", and "collect2: error: ld returned 1 exit status".

Here is part of my makefile, a simple makefile:

OBJS = median.o EventParam.o Filter.o OtdrAlgo.o Otdr.o \
       OtdrEdma.o OtdrMain.o OtdrTable.o NetworkSocket.o \
       Utility.o OtdrTouch.o Event.o

CFLAGS = -g -Wall
LDFLAGS = -lm -lpthread

#CROSS_COMPILE = /opt/itop/4.3.2/bin/arm-linux-

linuxotdr: $(OBJS)
    $(CROSS_COMPILE)gcc $(CFLAGS) $(LDFLAGS) -o $@ $^

Event.o : Event.c Otdr.h prototypes.h protocol.h DspFpgaReg.h
    $(CROSS_COMPILE)gcc -c $(CFLAGS)   $^
.........

I don't know how to solve it, could you help me?
Thanks very much.





 
_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make
Reply | Threaded
Open this post in threaded view
|

Re: GNU make 4.1 does not load libpthread

Yann Droneaud
Le mardi 06 septembre 2016 à 08:30 +0800, 彭怀敏 a écrit :
> Hi, I am using Ubuntu16.04, with GNU make 4.1.
> I was failed while built my project which referenced to libpthread
> and libm, but it was OK while used Ubuntu10.04 with GNU make 3.81.
> I found the difference of the "strace make" output between the two
> versions of make, that LD will open libpthread after open libc in
> v3.81, but it will not open libpthread in v4.1, and thus I got a lot
> of "undefined reference to", and "collect2: error: ld returned 1 exit
> status".
>

It's likely not related to make: your toolchains (binutils, gcc) and
libraries are differents between Ubuntu from 2010 and Ubuntu from 2014.

> Here is part of my makefile, a simple makefile:
>
> OBJS = median.o EventParam.o Filter.o OtdrAlgo.o Otdr.o \
>        OtdrEdma.o OtdrMain.o OtdrTable.o NetworkSocket.o \
>        Utility.o OtdrTouch.o Event.o
>
> CFLAGS = -g -Wall
> LDFLAGS = -lm -lpthread
>

-lm -lpthread should not be in variable $(LDFLAGS) as it's passed
before the object file to link.

For example, put them in $(LIBS)

LIBS := -lm -lpthread


> #CROSS_COMPILE = /opt/itop/4.3.2/bin/arm-linux-
>
> linuxotdr: $(OBJS)
>     $(CROSS_COMPILE)gcc $(CFLAGS) $(LDFLAGS) -o $@ $^
>

Libraries should be listed after the object files that might need them:

With the previous change, use recipe instead:

        $(CROSS_COMPILE)gcc $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)


> Event.o : Event.c Otdr.h prototypes.h protocol.h DspFpgaReg.h
>     $(CROSS_COMPILE)gcc -c $(CFLAGS)   $^
> .........
>
> I don't know how to solve it, could you help me?
> Thanks very much.
>
>

Regards.

-- 
Yann Droneaud
OPTEYA


_______________________________________________
Help-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-make