gcc newly installed libraries (libexpat1-dev) not recognised in current terminal (debian) - gcc

I've spent quite a bit of time trying to get an expat based sample program to compile.
I was receiving the following error message when I tried to compile
gcc -Wall -lexpat line.c -o blah
line.c: In function ‘main’:
line.c:99:8: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘XML_Size’ [-Wformat]
/tmp/ccUa3vfD.o: In function `printcurrent':
line.c:(.text+0x42): undefined reference to `XML_SetDefaultHandler'
line.c:(.text+0x4d): undefined reference to `XML_DefaultCurrent'
line.c:(.text+0x60): undefined reference to `XML_SetDefaultHandler'
/tmp/ccUa3vfD.o: In function `main':
line.c:(.text+0x162): undefined reference to `XML_ParserCreate'
line.c:(.text+0x1ad): undefined reference to `XML_UseParserAsHandlerArg'
line.c:(.text+0x1c9): undefined reference to `XML_SetElementHandler'
line.c:(.text+0x1dd): undefined reference to `XML_SetCharacterDataHandler'
line.c:(.text+0x1f1): undefined reference to `XML_SetProcessingInstructionHandler'
line.c:(.text+0x2b2): undefined reference to `XML_Parse'
line.c:(.text+0x2c2): undefined reference to `XML_GetErrorCode'
line.c:(.text+0x2ca): undefined reference to `XML_ErrorString'
line.c:(.text+0x2d8): undefined reference to `XML_GetCurrentLineNumber'
collect2: ld returned 1 exit status
I had already run the following commands:
sudo apt-get install expat libexpat1 libexpat1-dev libxmltok1-dev
So I messed around for ages, trying to get the error message to go away so I could compile this (simple) little program, but to no avail.
Eventually, out of sheer randomness, I decided to switch to a Virtual Terminal.
I ran exactly the same command, this time it worked without a problem.
Can anyone tell me why this is? Is there something I need to run in order to refresh the library paths?

The linker line (i.e. the flags you give with -l and your input file names) are order-dependent. Libraries are only used to define functions used on their left side, but not on their right. Use:
gcc -Wall line.c -lexpat -o blah
See the question library is linked but reference is undefined for more information.

Related

X11 linking issue potentially musl libc related

I am running Alpine Linux with musl libc attempting to install-
https://github.com/patrickhaller/no-wm/
with-
make install
I have musl-dev and libx11-dev installed.
libx11-dev puts libs in /usr/lib not /usr/X11/lib. see-
https://pkgs.alpinelinux.org/contents?branch=edge&name=libx11-dev&arch=x86&repo=main
So I changed the Makefile line to-
X11LIB = -lX11 -L/usr/lib/
I confirmed libX11.so is at that directory location.
Yet my install still fails with this output-
$ make install
gcc -O2 -Wall -std=c99 -pedantic -lX11 -L/usr/lib/ x-alt-tab-mru.c -o x-alt-tab-mru
/usr/lib/gcc/aarch64-alpine-linux-musl/10.2.0/../../../../aarch64-alpine-linux-musl/bin/ld: /tmp/cckobJdo.o: in function `x_alt_tab':
x-alt-tab-mru.c:(.text+0x70): undefined reference to `XGetWMHints'
/usr/lib/gcc/aarch64-alpine-linux-musl/10.2.0/../../../../aarch64-alpine-linux-musl/bin/ld: x-alt-tab-mru.c:(.text+0x84): undefined reference to `XGetWindowAttributes'
/usr/lib/gcc/aarch64-alpine-linux-musl/10.2.0/../../../../aarch64-alpine-linux-musl/bin/ld: x-alt-tab-mru.c:(.text+0xec): undefined reference to `XLowerWindow'
/usr/lib/gcc/aarch64-alpine-linux-musl/10.2.0/../../../../aarch64-alpine-linux-musl/bin/ld: x-alt-tab-mru.c:(.text+0xf8): undefined reference to `XRaiseWindow'
/usr/lib/gcc/aarch64-alpine-linux-musl/10.2.0/../../../../aarch64-alpine-linux-musl/bin/ld: x-alt-tab-mru.c:(.text+0x10c): undefined reference to `XSetInputFocus'
/usr/lib/gcc/aarch64-alpine-linux-musl/10.2.0/../../../../aarch64-alpine-linux-musl/bin/ld: x-alt-tab-mru.c:(.text+0x11c): undefined reference to `XRestackWindows'
/usr/lib/gcc/aarch64-alpine-linux-musl/10.2.0/../../../../aarch64-alpine-linux-musl/bin/ld: x-alt-tab-mru.c:(.text+0x128): undefined reference to `XSync'
/usr/lib/gcc/aarch64-alpine-linux-musl/10.2.0/../../../../aarch64-alpine-linux-musl/bin/ld: /tmp/cckobJdo.o: in function `main':
x-alt-tab-mru.c:(.text.startup+0x34): undefined reference to `XOpenDisplay'
/usr/lib/gcc/aarch64-alpine-linux-musl/10.2.0/../../../../aarch64-alpine-linux-musl/bin/ld: x-alt-tab-mru.c:(.text.startup+0x44): undefined reference to `XSync'
/usr/lib/gcc/aarch64-alpine-linux-musl/10.2.0/../../../../aarch64-alpine-linux-musl/bin/ld: x-alt-tab-mru.c:(.text.startup+0x70): undefined reference to `XQueryTree'
collect2: error: ld returned 1 exit status
make: *** [Makefile:19: x-alt-tab-mru] Error 1
I've confirmed the headers in that x-alt-tab-mru.c file are present in the correct location and were included with libx11-dev.
What can I do next to troubleshoot this and get it to compile? I've chased down everything I could think of..
The order of arguments on the link command line is significant. -L options apply only to searching for libraries designated later on the command line, and, at least for static linking, undefined symbols in one object among those being linked are resolved only against other objects designated later on the command line. Behavior may (or may not) vary a bit when linking shared libraries, but to be safe, you should always order the objects to be linked (source files, object files, and libraries) according to their dependencies.
In particular, then,
in the unlikely event that you need -L/usr/lib at all, it should come before -lX11, and
the -lX11 option should appear after x-alt-tab-mru.c in the link command.

MINGW64 cannot find reference to libcrypt

I have problem with building my C++ project using CLion, MINGw64.
So this is the problem I cannot handle with ._.
Everything works on Linux but on Win10 I have this log:
libBiblioteka.a(Rent.cpp.obj): In function `boost::uuids::detail::random_provider_base::random_provider_base()':
C:/msys64/mingw64/include/boost/uuid/detail/random_provider_bcrypt.ipp:40: undefined reference to `BCryptOpenAlgorithmProvider'
libBiblioteka.a(Rent.cpp.obj): In function `boost::uuids::detail::random_provider_base::get_random_bytes(void*, unsigned long long)':
C:/msys64/mingw64/include/boost/uuid/detail/random_provider_bcrypt.ipp:76: undefined reference to `BCryptGenRandom'
libBiblioteka.a(Rent.cpp.obj): In function `boost::uuids::detail::random_provider_base::destroy()':
C:/msys64/mingw64/include/boost/uuid/detail/random_provider_bcrypt.ipp:93: undefined reference to `BCryptCloseAlgorithmProvider'
collect2.exe: error: ld returned 1 exit status
I have read these references are unavaiable on win10. But there is an question:
Is there any way to workaround this?
Those are not defined in libcrypt but in libbcrypt.
Did you have the same typo in your linker flags (you should have -lbcrypt)?

GCC ICU 57 static linking

I am trying to link ICU 57 to my binary file. That does not work even thought (I think at least) I am linking the static lib files.
Here is a blunt example:
gcc -static /usr/lib/libicui18n.a /usr/lib/libicuuc.a /usr/lib/libicudata.a /usr/lib/libicule.a /usr/lib/libiculx.a /usr/lib/libicutu.a /usr/lib/libicuuc.a /usr/lib/libicuio.a obj/ex.o obj/msg.o -o bin/ex
This is the error message that I get:
src/msg.c:5: undefined reference to `u_fopen_57'
src/msg.c:9: undefined reference to `u_fgetfile_57'
src/msg.c:10: undefined reference to `u_fgetfile_57'
src/msg.c:11: undefined reference to `u_frewind_57'
src/msg.c:18: undefined reference to `u_fgetc_57'
src/msg.c:17: undefined reference to `u_feof_57'
src/msg.c:25: undefined reference to `u_fclose_57'
Linking the dynamic libs works fine though.
If you can, I'd recommend using pkg-config as I recommended here,
specifically with pkg-config --static … as explained here

Error while compiling Mono Source Tree on CentOS - 6.X

I want to install a latest Mono version on my CentOS (i686). As there is no ready to use binary distribution I tried to pull the latest Mono Source 3.2.3 from here. After pulling the source, I extracted it, change directory to it and tried below sequence of commands -
[root#localhost mono-3.2.3]# ./configure
No problems reported
[root#localhost mono-3.2.3]# make
make[3]: Entering directory `/usr/local/src/mono-3.2.3/mono/metadata'
CCLD pedump
./.libs/libmonoruntime.a(libmonoruntime_la-assembly.o): In function `InterlockedDecrement':
/usr/local/src/mono-3.2.3/mono/metadata/../../mono/utils/atomic.h:66: undefined reference to `__sync_add_and_fetch_4'
./.libs/libmonoruntime.a(libmonoruntime_la-assembly.o): In function `InterlockedIncrement':
/usr/local/src/mono-3.2.3/mono/metadata/../../mono/utils/atomic.h:61: undefined reference to `__sync_add_and_fetch_4'
./.libs/libmonoruntime.a(libmonoruntime_la-cominterop.o): In function `InterlockedDecrement':
/usr/local/src/mono-3.2.3/mono/metadata/../../mono/utils/atomic.h:66: undefined reference to `__sync_add_and_fetch_4'
./.libs/libmonoruntime.a(libmonoruntime_la-cominterop.o): In function `InterlockedIncrement':
/usr/local/src/mono-3.2.3/mono/metadata/../../mono/utils/atomic.h:61: undefined reference to `__sync_add_and_fetch_4'
./.libs/libmonoruntime.a(libmonoruntime_la-cominterop.o): In function `InterlockedDecrement':
/usr/local/src/mono-3.2.3/mono/metadata/../../mono/utils/atomic.h:66: undefined reference to `__sync_add_and_fetch_4'
./.libs/libmonoruntime.a(libmonoruntime_la-image.o):/usr/local/src/mono-3.2.3/mono/metadata/../../mono/utils/atomic.h:61: more undefined references to `__sync_add_and_fetch_4' follow
./.libs/libmonoruntime.a(libmonoruntime_la-marshal.o): In function `InterlockedCompareExchangePointer':
/usr/local/src/mono-3.2.3/mono/metadata/../../mono/utils/atomic.h:56: undefined reference to `__sync_val_compare_and_swap_4'
./.libs/libmonoruntime.a(libmonoruntime_la-marshal.o): In function `InterlockedExchangePointer':
While trying to resolve this I found this,this and this. I tried to implement the solution mentioned there but had no luck.
Has anybody faced this?
Regards,
Omky
I added two compiler switches in make file.
CPPFLAGS = -m32 -march=i686
This worked for me.

Suricata luajit compilation error

I'm currently trying to compile suricata (http://suricata-ids.org/) with luajit support on my arch linux distribution with these commands:
./configure --enable-luajit --with-libpcap-includes=/usr/local/pfring/include \
--with-libpcap-libraries=/usr/local/pfring/lib --with-libnss-libraries=/usr/lib \
--with-libnss-includes=/usr/include/nss/ --with-libnspr-libraries=/usr/lib \
--with-libnspr-includes=/usr/include/nspr \
--with-libluajit-includes=/usr/local/include/luajit-2.0/ \
--with-libluajit-libraries=/usr/lib/
then:
make
but I get the following errors when I make the project:
detect-luajit.o: In function `LuaDumpStack':
detect-luajit.c:(.text+0x46e): undefined reference to `lua_tonumberx'
detect-luajit.o: In function `DetectLuajitMatchBuffer':
detect-luajit.c:(.text+0x5d6): undefined reference to `lua_getglobal'
detect-luajit.c:(.text+0x6b9): undefined reference to `lua_pcallk'
detect-luajit.c:(.text+0x7d5): undefined reference to `lua_tonumberx'
detect-luajit.o: In function `DetectLuajitMatch':
detect-luajit.c:(.text+0xaac): undefined reference to `lua_getglobal'
detect-luajit.c:(.text+0xde4): undefined reference to `lua_pcallk'
detect-luajit.c:(.text+0xf00): undefined reference to `lua_tonumberx'
detect-luajit.o: In function `DetectLuajitThreadInit':
detect-luajit.c:(.text+0x1864): undefined reference to `lua_pcallk'
detect-luajit.o: In function `DetectLuaSetupPrime':
detect-luajit.c:(.text+0x1fe7): undefined reference to `lua_pcallk'
detect-luajit.c:(.text+0x2167): undefined reference to `lua_getglobal'
detect-luajit.c:(.text+0x24bf): undefined reference to `lua_pcallk'
collect2: error: ld returned 1 exit status
make[2]: *** [suricata] Error 1
I first though it was an issue coming from the lua version. So I tried to install both the lua 5.1.5 and 5.2.2, remaking the library and symbolic links as well, and nothing worked.
Thanks for your help
In Debian and Ubuntu, the library files are installed into /usr/lib/x86_64-linux-gnu/. If arch does the same, your configure line should include: --with-libluajit-libraries=/usr/lib/x86_64-linux-gnu/

Resources