gcc linker issue - gcc

I am trying to make a library that wraps libpurple (you shouldn't need to know anything about libpurple to help here). Libpurple in turn loads "plugins" which are just .so's accessed via something like dlopen. Those plugins in turn call back to functions in libpurple.
I can build my library just fine, but when it calls the appropriate libpurple init function, and libpurple tries to load a plugin, I get an error like the following:
symbol lookup error: /usr/local/lib/purple-2/autoaccept.so: undefined
symbol: purple_user_dir
purple_user_dir is a function defined in libpurple. When I build a program (not a library) that links to libpurple there are no problems. I have tried using -export-dynamic and that did not seem to help. Here is my build command:
gcc -export-dynamic -I/usr/local/include/libpurple -I/usr/include/python2.5 -DH\
AVE_CONFIG_H -I. -DSTANDALONE -DBR_PTHREADS=0 -DDATADIR=\"/usr/local/share\" -D\
LIBDIR=\"/usr/local/lib/purple-2/\" -DLOCALEDIR=\"/usr/local/share/locale\" -DS\
YSCONFDIR=\"/usr/local/etc\" -Wall -Waggregate-return -Wcast-align -Wdeclarati\
on-after-statement -Wendif-labels -Werror-implicit-function-declaration -Wextra\
-Wno-sign-compare -Wno-unused-parameter -Winit-self -Wmissing-declarations -Wm\
issing-noreturn -Wmissing-prototypes -Wpointer-arith -Wundef -Wp,-D_FORTIFY_SOU\
RCE=2 -pthread -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/inc\
lude/dbus-1.0 -I/usr/lib/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/gl\
ib-2.0/include -I/usr/include/libxml2 -g -g -O2 -c -o spurple.o spurple.c
gcc -shared -g -O2 -Wl,--export-dynamic -pthread
../../libpurple/.libs/libpurple.so -o spurple.so spurple.o
-Wl,--export-dynamic /usr/local/lib/libpurple.so
-ldbus-glib-1 -ldbus-1 /usr/lib/libgobject-2.0.so /usr/lib/libgmodule-2.0.so
-ldl /usr/lib/libgthread-2.0.so -lrt /usr/lib/libglib-2.0.so
/usr/lib/libxml2.so -lm -lpython2.5 -lutil -lpthread -lnsl -lresolv
Thanks.

I would try to use the ldd and nm unix commands to look for the symbols in the wrapper and wrapped libraries.

Just a shot in the dark, but do you have a different LD_LIBRARY_PATH environment variable when you build the app than when you run it?

Related

Movesense With nRF5_SDK : undefined reference to `__locale_ctype_ptr'

I am in my first compilation using the accelerometer_app example. Ninja crashes in step 1. It seems to be due to a problem with the linking process. Here is the output.
PS G:\Cardiovelo_sur_NAS\Laboratoires\Labo_TI\Labo_Movesense\movesense-device-lib\myBuild> ninja
[1/1] Linking CXX executable Movesense
FAILED: Movesense
cmd.exe /C "cd . && C:\PROGRA~2\GNUTOO~1\92019-~1\bin\AR19DD~1.EXE -W -Wall -Werror -Wfatal-errors -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wunreachable-code -Wsign-compare -Wno-aggregate-return -Wno-unused-parameter -Wno-unused-function -Wno-cast-align -Wno-strict-aliasing -Wno-maybe-uninitialized -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fno-common -ffreestanding -fno-builtin -mapcs -gdwarf-3 -std=gnu++11 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-unwind-tables -fno-use-cxa-atexit -fno-threadsafe-statics -Wno-old-style-declaration -Wno-discarded-qualifiers -Wp,-w -Wno-write-strings -U__INT32_TYPE__ -D__INT32_TYPE__=int -U__UINT32_TYPE__ -D__UINT32_TYPE__="unsigned int" -Os -g -DWB_UNITTEST_BUILD -Wl,--wrap -Wl,_malloc_r -Wl,--wrap -Wl,_calloc_r -Wl,--wrap -Wl,_free_r -Wl,--wrap -Wl,_realloc_r --specs=nano.specs --specs=nosys.specs -Wl,-Map -Wl,target.map -Wl,--gc-sections -Wl,-static -LG:/Cardiovelo_sur_NAS/Laboratoires/Labo_TI/Labo_Movesense/movesense-device-lib/MovesenseCoreLib/app-build/compiler/../platform/nRF5x/linker/gcc -TG:/Cardiovelo_sur_NAS/Laboratoires/Labo_TI/Labo_Movesense/movesense-device-lib/MovesenseCoreLib/app-build/compiler/../platform/nRF5x/linker/gcc/appflash.ld CMakeFiles/Movesense.dir/AccelerometerSampleService.cpp.obj CMakeFiles/Movesense.dir/App.cpp.obj CMakeFiles/Movesense.dir/generated/sbem-code/sbem_definitions.cpp.obj CMakeFiles/Movesense.dir/generated/app-resources/resources.cpp.obj CMakeFiles/Movesense.dir/app-metadata/metadata.cpp.obj -o Movesense G:/Cardiovelo_sur_NAS/Laboratoires/Labo_TI/Labo_Movesense/movesense-device-lib/MovesenseCoreLib/lib/GCCARM/libmovesense-coreD.a -lm -lstdc++ && cd ."
c:/progra~2/gnutoo~1/92019-~1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: G:/Cardiovelo_sur_NAS/Laboratoires/Labo_TI/Labo_Movesense/movesense-device-lib/MovesenseCoreLib/lib/GCCARM/libmovesense-coreD.a(nrf_log_backend_serial.c.obj): in function `nrf_log_backend_serial_hexdump_handler':
E:\BuildAgent\work\939b802005569609\vendor\nRF5_SDK\components\libraries\log\src/nrf_log_backend_serial.c:446: undefined reference to `__locale_ctype_ptr'
c:/progra~2/gnutoo~1/92019-~1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: G:/Cardiovelo_sur_NAS/Laboratoires/Labo_TI/Labo_Movesense/movesense-device-lib/MovesenseCoreLib/lib/GCCARM/libmovesense-coreD.a(manufacturingdata.c.obj): in function `store_pcba_string':
E:\BuildAgent\work\939b802005569609\nea\hal\manufacturingdata/manufacturingdata.c:926: undefined reference to `__locale_ctype_ptr'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed
The first error is:
E:\BuildAgent\work\939b802005569609\vendor\nRF5_SDK\components\libraries\log\src/nrf_log_backend_serial.c:446: undefined reference to `__locale_ctype_ptr'
I installed nrfutil (version 6.0.1) on python 2.7.9 (default version on my PC).
Obviously, there is something that does not work and I need help to solve the problem.
OKAY. The problem was 18 "in front of the screen! I had installed the wrong version of the GNU Toolchain for ARM Embedded compiler. However, it was well written to choose the 2017q4 version.
The subject can be considered closed.

Negate previous -D[efine] flag for GCC

Under GNUStep on Arch Linux, I'm running into an interesting error on a fresh install.
Using my build system I run
gcc `gnustep-config --debug-flags` [other command line args]
in order to build up the command line per the operating system's necessary flags.
This works fine under Ubuntu, but on Arch Linux I'm getting a rather random error:
/usr/include/features.h:328:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
Well, gnustep-config --debug-flags spits out the following:
-MMD -MP -D_FORTIFY_SOURCE=2 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fno-strict-aliasing -pthread -fPIC -g -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -march=x86-64 -mtune=generic -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -fgnu-runtime -fconstant-string-class=NSConstantString -fexec-charset=UTF-8 -I. -I/home/qix/GNUstep/Library/Headers -I/usr/include -D_FORTIFY_SOURCE=2 -I/usr/include -I/usr/include -I/usr/include -I/usr/lib/libffi-3.1/include/ -I/usr/lib/libffi-3.1/include -I/usr/include/libxml2 -I/usr/include/p11-kit-1
As well, I wish not to have optimizations on my debug builds (and later on I even override GNUStep's -g parameter to -g2).
Is there a way to explicitly undefine -D_FORTIFY_SOURCE later on in the command line, after the call to gnustep-config?
For example, something like
gcc `gnustep-config --debug-flags` -U_FORTIFY_SOURCE ...
where the -U undefines the previously defined macro?
Something to mention; I have -Werror enabled on purpose, and I'd like to keep it.
For now, using sed to work around this works. It appears this is a known issue with _FORTIFY_SOURCE causing issues, and there isn't a straightforward fix.
`gnustep-config --debug-flags | sed 's/-D_FORTIFY_SOURCE=2//g'`

How to compile boost async_client.cpp

What is the correct command to compile this code?
http://www.boost.org/doc/libs/1_45_0/doc/html/boost_asio/example/http/client/async_client.cpp
I had installed boost library in /usr/include/boost
E.g.
clang++ -std=c++03 -Wall -pedantic -g -O2 async_client.cpp -o async_client -lboost_system -lboost_thread -lpthread
Assuming your system's packaged version of Boost (or pre-configured include & lib paths). To make use of your custom built Boost library tree in ~/custom/boost:
clang++ -std=c++03 -Wall -pedantic -g -O2 \
-isystem ~/custom/boost/ ~/custom/boost/libs/asio/example/cpp03/http/client/ \
async_client.cpp -o async_client \
-L ~/custom/boost/stage/lib/ -Wl,-rpath,/home/sehe/custom/boost/stage/lib \
-lboost_system -lboost_thread -lpthread
Replace clang++ by g++ at will.
-std=c++03 -Wall -pedantic -g -O2 only for expositional purposes.

Error exporting symbol when cross-compiling ICU for Windows.

I am attempting to use Mingw-w64's 32-bit compiler (the i686-w64-mingw32 toolchain) to cross-compile the ICU library for Windows. The host is Ubuntu 12.10 64-bit.
The steps I have taken look something like this:
Grab the latest source code archive from here and extract it.
Make two copies of the source/ directory - one for the host and one for the target.
For the host build:
./configure ; make
For the target build:
./configure --host=i686-w64-mingw32 --with-cross-build=<host_source_dir>
...where <host_source_dir> is the directory from the previous step.
When I run make in the target source directory, compilation proceeds without any errors for a few moments and then throws this error:
i686-w64-mingw32-g++ -O2 -W -Wall -pedantic -Wpointer-arith -Wwrite-strings
-Wno-long-long -mthreads -o ../../bin/uconv.exe uconv.o uwmsg.o
-L../../lib -licuin50 -L../../lib -licuuc50 -L../../stubdata -licudt50
-lm uconvmsg/uconvmsg.a
uconv.o:uconv.cpp:(.text+0x2f): undefined reference to `_uconvmsg_dat'
What could be causing this error? I backed up a few lines and also noticed this:
pkgdata: i686-w64-mingw32-gcc -O2 -Wall -std=c99 -pedantic -Wshadow
-Wpointer-arith -Wmissing-prototypes -Wwrite-strings -mthreads -shared
-Wl,-Bsymbolic -Wl,--enable-auto-import -Wl,--out-implib=./all.lib -o
../lib/icudt50.dll ./out/tmp/icudt50l_dat.o
Cannot export icudt50_dat: symbol not found
collect2: ld returned 1 exit status
-- return status = 256
Error generating library file. Failed command: i686-w64-mingw32-gcc -O2 -Wall
-std=c99 -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes
-Wwrite-strings -mthreads -shared -Wl,-Bsymbolic -Wl,--enable-auto-import
-Wl,--out-implib=./all.lib -o ../lib/icudt50.dll ./out/tmp/icudt50l_dat.o
Error generating assembly code for data.
What am I doing wrong?
In order to debug your symbol problem just provide the flag -Wl,--trace-symbol=_uconvmsg_dat to i686-w64-mingw32-g++ like follows:
i686-w64-mingw32-g++ -O2 -W -Wall -pedantic -Wpointer-arith -Wwrite-strings
-Wno-long-long -mthreads -o ../../bin/uconv.exe uconv.o uwmsg.o
-L../../lib -licuin50 -L../../lib -licuuc50 -L../../stubdata -licudt50
-lm uconvmsg/uconvmsg.a -Wl,--trace-symbol=_uconvmsg_dat
So it turns out that the problem was indeed with the ICU source code. I'm not sure I understand exactly what the problem is, but thankfully someone else did and wrote three patches.
The first two apply to my question above:
icu4c-50_1_2-crossbuild.patch
icu4c-4_6_1-win32.patch
The third patch is used instead of the second in the list above when building for the x86_64 architecture:
icu4c-4_6_1-win64.patch
There does still seem to be a problem when running make install, but at least the source tree seems to build now.

Gnu Octave build error under MinGW/MSYS

I'm trying to build Gnu Octave for Windows.I built all the main dependencies without having much problem.And configuring process went well.But when I tried to run make(After few source modifications to get over some errors),It triggers tons of errors like
./.libs/liboctinterp.a(liboctinterp_la-octave.o): In function `safe_source_file':
C:\MinGW\sources\octave-3.6.2\src/octave.cc:312: undefined reference to `___cxa_begin_catch'
At the line
libtool: link: gcc -g -O2 -pthread -DHAVE_CONFIG_H -mieee-fp -Wall -W -Wshadow -Wformat -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wcast-align -Wcast-qual -g -O2 -pthread -pthread -g -O2 -pthread -o .libs/octave.exe main.o ./.libs/liboctinterp.a /mingw/sources/octave-3.6.2~~/liboctave/.libs/liboctave.a -L=c:/mingw/bin/../lib/gcc/mingw32/4.7.0 -L=c:/mingw/bin/../lib/gcc -L=c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/lib -L=c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../.. -lfltk_gl -lfltk -lole32 -luuid -lcomctl32 -LC:/MinGW/lib /mingw/lib/libfontconfig.dll.a -L=C:/MinGW/lib /mingw/lib/libfreetype.dll.a -lz -lbz2 /mingw/lib/libexpat.dll.a -lopengl32 -lglu32 ../liboctave/.libs/liboctave.a /mingw/sources/octave-3.6.2~~/libcruft/.libs/libcruft.a /mingw/lib/libarpack.a /mingw/lib/libfftw3.a -lreadline -ltermcap /mingw/lib/libpcre.dll.a ../libcruft/.libs/libcruft.a -llapack -lblas -lgfortran -lquadmath -liberty -lgdi32 -lws2_32 -luser32 -lkernel32 -pthread -L/mingw/lib
I dumped the make log to a file and the file is about 39MB!! Just full of errors like above.
I'm very much thankful if someone can help me to get over this.

Resources