Undefined reference to symbol 'socket@@GLIBC_2.4'

Hi all,

I am trying to compile an application that will run on a Colibri i.MX7 with Linux BSP5.7 that is customized via Yocto.
After successfully compiling and running a simple “hello world” program, I’m now compiling the “real” application that I want to run.
This application is using sockets to implement a TCP server.

When linking I get the following error:

Building target: API-terminal
Invoking: Cross G++ Linker
arm-tdx-linux-gnueabi-ld  --sysroot=/opt/tdx-xwayland/5.7.1/sysroots/armv7at2hf-neon-tdx-linux-gnueabi -Lusr/lib -O1,--hash-style=gnu -o "API-terminal" ./src/API-terminal.o ./src/command_terminal.o ./src/console_server.o  ./Interferometer_API/src/M4.o ./Interferometer_API/src/MCP41xxx.o ./Interferometer_API/src/MCP48CxB11.o ./Interferometer_API/src/acquisition.o ./Interferometer_API/src/gpio.o ./Interferometer_API/src/gps.o ./Interferometer_API/src/gpt.o ./Interferometer_API/src/i2c.o ./Interferometer_API/src/iio_utils.o ./Interferometer_API/src/laser.o ./Interferometer_API/src/pga.o ./Interferometer_API/src/sinus.o ./Interferometer_API/src/spi.o    -lpthread -lgpiod
arm-tdx-linux-gnueabi-ld: ./src/console_server.o: undefined reference to symbol 'socket@@GLIBC_2.4'
arm-tdx-linux-gnueabi-ld: /opt/tdx-xwayland/5.7.1/sysroots/armv7at2hf-neon-tdx-linux-gnueabi/lib/libc.so.6: error adding symbols: DSO missing from command line
make: *** [makefile:59: API-terminal] Error 1

As you can see from the ld command line, the root directory for libraries is /opt/tdx-xwayland/5.7.1/sysroots/armv7at2hf-neon-tdx-linux-gnueabi . The contents of this directory are generated by Yocto (bitbake tdx-reference-minimal-image -c populate_sdk) and installed from oe-core/build/deploy/sdk/ by running the .sh file in that directory.

As far as I know, the socket API is supposed to be in one of the default libraries that ld will use but apparently this is not the case.
Can anyone tell me which library to add in order to include the socket API ?
Or alternatively, why the socket API is not present in the standard libraries…

Many thanks in advance,

Hello @ompie ,
I found this, it might help:

Best regards,

Hi @josep.tx,

Thanks for your reply.
I already found the post you mentioned but it did not solve my problem. First of all, there is no -nostdlib option to the linker.
I did however try to add the libraries suggested in the post but that did not help.

Best regards,

Hi @ompie !

Would you be able to try to build the same application in Yocto, by creating a recipe for it?

Just to test if it will be built or not.

Best regards,

Hi @henrique.tx,
Not sure that I will be able to do this easily. I’m quite new to Yocto and while already having some issues with the building of my image, I would like to avoid adding additional complexity for now. Especially because the application consists of several files in multiple directories.

However, I realized that one of the differences between my “real” application and the “hello world” example is the fact that my applicant is a C++ program, which possible changes some naming conventions for functions.
To confirm that, I added some calls to socket related functions (socket(), setsockopt(), bind(), etc.) to the “Hello world” program and compiled and ran it without problems.

=> So the problem is C++ naming I guess
(the application used to compile and run when I used Visual Studio code + Docker on Torizon, but that was before I had to abandon Torizon because of lack of RPMsg/OpenAMP support…)

I did a try by adding ‘extern “C”’ in the socket.h file (in the SDK generated by Yocto, and installed under /opt/tdx-xwayland/5.7.1/sysroots/armv7at2hf-neon-tdx-linux-gnueabi/usr/include/sys, but without any changes in the error message.

Next step was to add my own definition of socket() to the .cpp file and not the linker does not complain about socket anymore but is missing symbol symbol ‘strcpy@@GLIBC_2.4’.

I finally solved the problem in a quite unexpected way. Earlier on, I modified the SDK environment setup file (the one that is executed before starting eclipse, i.e. /opt/tdx-xwayland/5.7.1/environment-setup-armv7at2hf-neon-tdx-linux-gnueabi in my case) because the linker complained about unrecognized options (-Wl, O1 for example).
Looking deeper in the cause of this, I learned that the -Wl prefix is used to pass linker option to gcc/g++. In my eclipse project, I specified ${LD} as the linker command.
=> Changing that to ${GXX} not only solved the options problem but also the missing symbols :slight_smile:

This post is therefore solved.


Hi @ompie !

Seems like your solution is somewhat aligned with the Archived Toradex Developer page (specifically Step 14): Configure Eclipse - Getting Started with Toradex

Thanks for sharing your solution with us! :smiley:

Best regards,