WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: gcc compiling C++ code  (Read 2929 times)

Offline asi3brg

  • Newbie
  • *
  • Posts: 9
gcc compiling C++ code
« on: January 16, 2020, 05:15:22 AM »
I've a c++ dll (.so) that I use to comunicate in a CAN-BUS via a PEAK CAN-FD interface.
Now I want to use this dll within Tiny Core but I'm facing errors compiling it with gcc (once in Tiny Core couldn't found g++ compiler).
Note: I used this dll in ubuntu, compiled with g++, now I tested compiling with gcc, also in ubuntu, and I got the same errors.
Atached I'm send errors generated by gcc compilattion in Tiny Core

Please let me know if you have some help or hint.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14815
Re: gcc compiling C++ code
« Reply #1 on: January 16, 2020, 06:03:07 AM »
Use the compiletc meta-extension to compile in tinycore - that being said, g++ is provided by the gcc extension.

Note that gcc and tinycore are compiled for a minimum cpu of i486.

You might need to define which c++ standard you wish to compile to.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: gcc compiling C++ code
« Reply #2 on: January 16, 2020, 08:41:12 AM »
Hi asi3brg
Welcome to the forum. From your attachment, try changing this:
Code: [Select]
gcc -static -g LibCAN.cpp GenericAux.cpp pcaninfo.c TimeOut.cpp -O0 -Wall -m32 -march=i386 -mtune=i386 -fno-stack-protector -fPIC -Wl,--no-undefined -shared -I/usr/include -I../../ -ldl  -o LibCAN.so to that:
Code: [Select]
gcc -static -g LibCAN.cpp GenericAux.cpp pcaninfo.c TimeOut.cpp -O0 -Wall -m32 -march=i386 -mtune=i386 -fno-stack-protector -fPIC -Wl,--no-undefined -shared -I/usr/include -I../../ -lstdc++ -lm -ldl  -o LibCAN.so
So you want to add  -lstdc++  and  -lm  to the make file, probably where it lists  -ldl.

Offline asi3brg

  • Newbie
  • *
  • Posts: 9
Re: gcc compiling C++ code
« Reply #3 on: January 16, 2020, 12:16:52 PM »
Hi Juanito,
Thank you for the fast reply.
After add -lstdc++  and  -lm only this error remains
Code: [Select]
tc@box:/home/BlBox_SW/LibCAN/LibCAN$ make
gcc -static -g LibCAN.cpp GenericAux.cpp pcaninfo.c TimeOut.cpp  -I/usr/include -I../../ -lstdc++ -lm -ldl  -o LibCAN.so       
/usr/local/bin/ld: /tmp/cccgs6Z3.o: in function `CANBasic::LoadDllSo()':
/home/BlBox_SW/LibCAN/LibCAN/LibCAN.cpp:635: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/bin/ld: /usr/lib/crt1.o: in function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
make: *** [Makefile:27: all] Error 1
tc@box:/home/BlBox_SW/LibCAN/LibCAN$

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: gcc compiling C++ code
« Reply #4 on: January 16, 2020, 12:36:14 PM »
Hi asi3brg
Do you have a  main  defined in any of your source files? If not, maybe you need to add:
Code: [Select]
-nostartfilesto your linker options.

Offline asi3brg

  • Newbie
  • *
  • Posts: 9
Re: gcc compiling C++ code
« Reply #5 on: January 17, 2020, 08:31:00 AM »
Hi Rich
Now I'm able to compile this shared object in Tiny Core.
Thank you for your excellent support.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: gcc compiling C++ code
« Reply #6 on: January 17, 2020, 08:51:07 AM »
Hi asi3brg
You are welcome. Thank you for confirming your success.