roty
Posts: 16
Joined: Sat Jun 12, 2021 7:15 am

GCC Linker problem

Mon Jun 14, 2021 6:02 am

Hello,

I'm using GCC Cross Compiler for RPi4 on Windows with Eclipse. It basically works, but now I'm struggling
with a linker problem after I added the GTK3 package . A very simple example works and can be executed
on the RPi4. But an other example fails and I have no idea what's wrong.

I'm getting two errors from linker:
...: undefined reference to symbol 'g_type_check _instance_cast'
and
.... arm-linux-gnuebaihf/libgobject-2.0.so.0: error adding symbols: DSO missing from command line[
I went through the web and I found a lot of hints about how to fix these issues, but nothing I could use in my case
helped me to fix it. Now I'm a bit lost.

Can anybody help anyhow?

Thank you very much.

Rob

User avatar
Paeryn
Posts: 3305
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: GCC Linker problem

Mon Jun 14, 2021 9:45 am

The error messages suggests that a library which provides the missing symbols hasn't been given to the linker. What was the command line you used to compile?

Basic usage of glib will just need the following adding to link line.

Code: Select all

$(pkg-config --libs glib-2.0)
But if you use gobject then change that to

Code: Select all

$(pkg-config --libs gobject-2.0)
When using pkg-config like above both the gobject and gmodule packages will bring in glib as well so you don't need to specify glib if you have already specified gobject.

Edit; Just realised you were attempting to link the GTK-3 libraries, I was basing the above just on what the error messages said.
In this case you need the following to make sure all the needed libraries for GTK-3 are linked in.

Code: Select all

$(pkg-config --libs gtk+-3.0)
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

roty
Posts: 16
Joined: Sat Jun 12, 2021 7:15 am

Re: GCC Linker problem

Mon Jun 14, 2021 10:29 am

  • Thank you for trying to help.

    Please consider, I'm using Eclipse and a managed project, so I have just limited options for adding
    make settings. For example this is the lib part of the generated make file.

    Code: Select all

    ################################################################################
    # Automatically-generated file. Do not edit!
    ################################################################################
    
    USER_OBJS :=
    
    LIBS := -lgtk-3 -lwiringPi -lpthread -lX11 -lgio-2.0  -lm
    
    
    Can you please advice where one of the mentioned libs must be added ?

    Thanks a lot

User avatar
Paeryn
Posts: 3305
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: GCC Linker problem

Mon Jun 14, 2021 10:56 am

I've not used Eclipse for a long time but a quick search with Google says you put the linker settings in
Project->Properties->C/C++ Build->Settings->Tool Settings
Then choose Cross GCC Linker->Libraries->Libraries and add the libraries needed there. You won't be able to use pkg-config there but if you run

Code: Select all

pkg-config --libs gtk+-3.0
In a terminal it will show you which libraries are needed (everything beginning with -l), add these to the Eclipse project without the -l, so where pkg-cong shows

Code: Select all

-lglib-2.0
You need to add glib-2.0. Do that for all the libraries (keeping then in the same order). If pkg-config showed any other flags (like -L) they will need adding to the relevant sections of your Eclipse project settings too.
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

roty
Posts: 16
Joined: Sat Jun 12, 2021 7:15 am

Re: GCC Linker problem

Mon Jun 14, 2021 11:09 am

Thank you for your effort and patiences.

Yes, I know where to add libaries and I did what you suggested. Now the LIB make part is:

Code: Select all

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

USER_OBJS :=

LIBS := -lglib-2.0 -lgtk-3 -lwiringPi -lpthread -lX11 -lgio-2.0 -lm
-L is not involved , as far as I noticed.

But unfortunately, I get the same errors.

User avatar
Paeryn
Posts: 3305
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: GCC Linker problem

Mon Jun 14, 2021 12:04 pm

roty wrote:
Mon Jun 14, 2021 11:09 am
Thank you for your effort and patiences.

Yes, I know where to add libaries and I did what you suggested. Now the LIB make part is:

Code: Select all

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

USER_OBJS :=

LIBS := -lglib-2.0 -lgtk-3 -lwiringPi -lpthread -lX11 -lgio-2.0 -lm
-L is not involved , as far as I noticed.

But unfortunately, I get the same errors.
That is nowhere near enough libraries, there are 11 needed for gtk-3 according to my RPi (appologies if these are mis-typed, I can't copy-paste from the terminal to my phone)

Code: Select all

$ pkg-config --libs gtk+-3.0
-lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
Also the order is important, libraries should be ordered such that a providing library appears after all libraries that use it. In your autogenerated Makefile it shows glib-2.0 before gtk+-3.0 which will mean that the glib symbols used by gtk-3 won't get resolved (and the Makefile doesn't even link in the gobject-2.0 library)
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

roty
Posts: 16
Joined: Sat Jun 12, 2021 7:15 am

Re: GCC Linker problem

Mon Jun 14, 2021 12:36 pm

Thank you,

I'll try that today, but it'll take some time because I first have to locate the libs at the RPi4 and to transfer them
to the Windows PC. I'll use the same order as you proposed.

I'll report, but possibly then tomorrow.

Thanks again for your support, I appreciate it very much.

roty
Posts: 16
Joined: Sat Jun 12, 2021 7:15 am

Re: GCC Linker problem

Mon Jun 14, 2021 6:20 pm

Dear Paeryn,

I can report success!

After a lot of work , finding the GTK libs at the RPi4 and after a long FTP session, all error are gone.

I would not have been able to find the solution without your help. Now I can continue with my project until the next problem ;)

Thank you really very much for your help.

Regards Rob

dsyleixa123
Posts: 1494
Joined: Mon Jun 11, 2018 11:22 am

Re: GCC Linker problem

Wed Jun 16, 2021 7:58 am

just our of interest:
do you need to cross-compile with Eclipse on a Windows PC for professional purposes and for different target boards?
Or why don't you just compile and build locally on the Pi?

roty
Posts: 16
Joined: Sat Jun 12, 2021 7:15 am

Re: GCC Linker problem

Wed Jun 16, 2021 8:26 am

I expected such a question ;) . I know all could be done on the RPi4B board.

But there are different reasons for my decision:

1. I'm rather familiar with Eclipse and the GCC Tools on Windows, because I also have a lot of projects with other MC's .
The current project would possible be just an exception (but I already noticed a lot of advantages using such a board and
the SW).
2. I often use similar or special code parts. These parts are meanwhile located in different repositories on my desktop Windows PC.
So for me I have better access and overview.
3. There are own boards with other MCs connected to RPi which must be debugged with other ICDs. I can do all the stuff from a
single desktop.
4. I just started with RPI and Linux , but I have no experiences with Linux right now.

It is in my opinion the best and fastest way to deal with all the circumstances.

Return to “C/C++”