Reputation: 809
I am trying to cross-compile the mosquitto example program. At first I compiled the mosquitto example on Host PC, it worked well. The makefile is as following:
CFLAGS=-Wall -ggdb -I../../lib -I../../lib/cpp
LDFLAGS=-L../../lib ../../lib/cpp/libmosquittopp.so.1 ../../lib/libmosquitto.so.1
.PHONY: all clean
all : mqtt_temperature_conversion
mqtt_temperature_conversion : main.o temperature_conversion.o
${CXX} $^ -o $@ ${LDFLAGS}
main.o : main.cpp
${CXX} -c $^ -o $@ ${CFLAGS}
temperature_conversion.o : temperature_conversion.cpp
${CXX} -c $^ -o $@ ${CFLAGS}
clean :
-rm -f *.o mqtt_temperature_conversion
Then I add the following lines to cross compile this program:
CXX=arm-unknown-linux-gnueabi-gcc
AR=arm-unknown-linux-gnueabi-ar
AS=arm-unknown-linux-gnueabi-as
LD=arm-unknown-linux-gnueabi-ld
RANLIB=arm-unknown-linux-gnueabi-ranlib
Then it gives a error message:
/home/Tools/tool_chain/bin/../lib/gcc/arm-unknown-linux-
gnueabi/5.4.0/../../../../arm-unknown-linux-gnueabi/bin/ld: main.o:
undefined reference to symbol '_ZdlPv@@GLIBCXX_3.4'
/home/Tools/tool_chain/bin/../sysroot/usr/lib/libstdc++.so.6:
error adding symbols: DSO missing from command line
I am very confused. I googled for this error, but none of them seems to be relevant. Cause when I compiled with the host PC compiler, everything works. So it should not be a lib problem.
update: So I could not figure out what happened, then I made a test project myself. The Makefile is as follows:(I ignored the cross tool chain variabl parts to save some place)
CFLAGS=-Wall -ggdb -I../../lib -I../../lib/cpp
LDFLAGS=-L../../lib ../../lib/cpp/libmosquittopp.so.1 ../../lib/libmosquitto.so.1
mqtt: main.o
${CXX} $^ -o $@ ${LDFLAGS}
main.o: main.cpp
${CXX} -c $^ -o $@ ${CFLAGS}
And it worked?! I flashed it to the board the executable seems to be correct.
Now I am more confused
Upvotes: 0
Views: 454
Reputation: 119877
LD=arm-unknown-linux-gnueabi-ld
Don't use ld
directly, ever. You want to use g++
as the driver that calls your linker, otherwise you will have linker problems.
LD=$(CXX)
Upvotes: 1