Raspberry Pi and NMEA2000 - Can't Compile

try this...

Code:
g++ -Wall -o main.o/home/pi/developer/NMEA2000_socketCAN/NMEA2000_SocketCAN.cpp  main.cpp  -I/home/pi/developer/NMEA2000/src/ -I/home/pi/developer/NMEA2000_socketCAN -L/home/pi/developer/NMEA2000/src/ -lnmea2000

effectively swapping the order of main.cpp and NMEA_SocketCAN.cpp

because the other 'library' isn't a 'library' you may find the order is important. Absolutely for certain the symbols from SocketCAN aren't present when the linker tries to resolve references ion main.cpp.

Update: It's a while since I used c++ so I checked. http://lampwww.epfl.ch/~fsalvi/docs/gcc/www.network-theory.co.uk/docs/gccintro/gccintro_14.html and https://stackoverflow.com/questions/11893996/why-does-the-order-of-l-option-in-gcc-matter confirm the linker is single pass
 
Last edited:
try this...

Code:
g++ -Wall -o main.o/home/pi/developer/NMEA2000_socketCAN/NMEA2000_SocketCAN.cpp  main.cpp  -I/home/pi/developer/NMEA2000/src/ -I/home/pi/developer/NMEA2000_socketCAN -L/home/pi/developer/NMEA2000/src/ -lnmea2000

effectively swapping the order of main.cpp and NMEA_SocketCAN.cpp

because the other 'library' isn't a 'library' you may find the order is important. Absolutely for certain the symbols from SocketCAN aren't present when the linker tries to resolve references ion main.cpp.

Update: It's a while since I used c++ so I checked. http://lampwww.epfl.ch/~fsalvi/docs/gcc/www.network-theory.co.uk/docs/gccintro/gccintro_14.html and https://stackoverflow.com/questions/11893996/why-does-the-order-of-l-option-in-gcc-matter confirm the linker is single pass

Hi SeaSpray, thanks for your help

Unfortunately that gives me this:
Code:
/tmp/cchFvZcZ.o: In function `tNMEA2000_SocketCAN::tNMEA2000_SocketCAN(char*)':
NMEA2000_SocketCAN.cpp:(.text+0x1c): undefined reference to `tNMEA2000::tNMEA2000()'
/tmp/cchFvZcZ.o:(.rodata+0xcc): undefined reference to `tNMEA2000::InitCANFrameBuffers()'
/tmp/cchFvZcZ.o:(.rodata+0xfc): undefined reference to `typeinfo for tNMEA2000'
/tmp/cctlsaIA.o: In function `main':
main.cpp:(.text+0x74): undefined reference to `tNMEA2000::Open()'
main.cpp:(.text+0xe8): undefined reference to `tNMEA2000::ParseMessages()'
collect2: error: ld returned 1 exit status
pi@opencpn:~/projects/nmea_reader $
 
Try with a space after main.o

The issue is that the linker reads each file once, if it reads a file before the file containing the function it uses, it throws that error.
 
Try with a space after main.o

The issue is that the linker reads each file once, if it reads a file before the file containing the function it uses, it throws that error.

Hi, I had put a space after the main.o, spotted that straight away.

I think I'm going to give up on this, and move on to something else. Thanks for all your help folks
 
Top