Skipping incompatible /lib/ when searching for /lib/

When cross-building a program (but this could also happen when building natively), it’s normal that we don’t have the environment variables and building flags set with the right paths that indicate where the toolchain and the sysroot are.

The wrong paths can lead to many types of building errors at different stages. This one happened to me recently:

This linking error says that it is skipping an incompatible library that is searching in my host’s filesystem even though I explicitly indicated in the Makefile the paths to use in the environment variable LDFLAGS with the -L:

The $SYSROOT environment variable was set correctly

To indicate the linker to use the right path you have to add the -Xlinker -rpath-link=/your/sysroot/path directives.

For adding the /lib and /usr/lib path that are in my sysroot, the previous setting of LDFLAGS becomes:

Now the linker does not complain anymore.

Failed to map segment from shared object

Recently, I was working with an AMD Geode LX800 with Debian 7.2 installed on it. I had a small CF and was running out of space, so I used an USB stick where I copied the binary to test (a Qt5 app) and when executing it as a normal user and as root I was getting the following error:

I play around with file ownership (chown) and access permissions (chmod), but nothing changed.

Later I realized that the problem was that the USB stick was mounted with the noexec flag.
Mounting it without this flag allows the shared library to be properly loaded.

Searching around I found that this issue can happen under other similar scenarios like network mounted drives that contain shared libraries that were mounted with the noexec option or simply the /tmp partition that is normally mounted in memory but without execution permissions.

Cross-compiling a custom Net-SNMP agent

Building the default agents in Net-SNMP is quite easy if you’re using tools such as Buildroot, and even when building directly from the sources is not a problem. However, is not that easy if you want to cross-build a custom agent inside Net-SNMP.

This procedure worked for me, but keep in mind that it was not a clean procedure since it involves modifying the generated Makefiles, so every time that you ./configure you will loose your changes.

First, let’s export common environment variables that make our life easier:


Package: net-snmp-


Instead of using the –with-cflags and –with-ldflags, you can define the CFLAGS and LDFLAGS:

The custom agent must be located inside the agent/mibgroup directory. In this case, create the directory agent/mibgroup/my_mib and write here the agent sources:

If these agent source use only libc it wouldn’t be an issue. But they use other libraries such as Glib2, SQLite3 and libxml2, thus we have to include these libraries by using the –with-cflags and –with-ldflags options or the CFLAGS and LDFLAGS environment variables.

However, when building, the linker didn’t find the GLib2, sqlite3 and libmlx2 shared libraries even though I specified the paths as above…
I got this kind of errors:

For solving this issue in a dirty but fast way, modify the files agent/Makefile and apps/Makefile. Set the LDFLAGS variable to the following value:

In this way you can quickly build your custom SNMP agent inside Net-SNMP.