Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Hidden symbols when static linking  (Read 2222 times)

0 Members and 1 Guest are viewing this topic.

jamesl22

  • Newbie
  • *
  • Posts: 4
    • View Profile
Hidden symbols when static linking
« on: June 11, 2018, 05:27:23 am »
Hello,

I use SFML in my project Cryptokernel for networking (https://github.com/mit-dci/CryptoKernel). I'm trying to produce static binaries for distribution on Linux, and whilst I have this working on Windows, I cannot link SFML statically on Linux.

I used the following to build SFML:

Code: [Select]
git clone https://github.com/SFML/SFML.git
cd SFML
cmake . -DBUILD_SHARED_LIBS=NO -DSFML_BUILD_DOC=NO -DSFML_BUILD_AUDIO=NO \
-DSFML_BUILD_GRAPHICS=NO -DSFML_BUILD_WINDOW=NO -DSFML_BUILD_EXAMPLES=NO \
-DCMAKE_BUILD_TYPE=Release
make && make install
cp /usr/local/lib/libsfml-network-s.a /usr/local/lib/libsfml-network.a && cp /usr/local/lib/libsfml-system-s.a /usr/local/lib/libsfml-system.a

But when linking my project (with -DSFML_STATIC):

Code: [Select]
/usr/bin/x86_64-linux-gnu-ld: ckd: hidden symbol `_ZN2sf9IpAddress15getLocalAddressEv' in /usr/local/lib/libsfml-network.a(IpAddress.cpp.o) is referenced by DSO
/usr/bin/x86_64-linux-gnu-ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

Using nm it doesn't seem to be hidden though:
Code: [Select]
...
                 U _ZN2sf4priv10SocketImpl13invalidSocketEv
                 U _ZN2sf4priv10SocketImpl5closeEi
                 U _ZN2sf6SocketD2Ev
0000000000000460 T _ZN2sf9IpAddress15getLocalAddressEv
00000000000009a0 T _ZN2sf9IpAddress16getPublicAddressENS_4TimeE
0000000000000010 B _ZN2sf9IpAddress3AnyE
0000000000000018 B _ZN2sf9IpAddress4NoneE
...

I would appreciate a pointer as to what could be going wrong here.

Thanks,

James
« Last Edit: June 11, 2018, 06:15:53 am by jamesl22 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Hidden symbols when static linking
« Reply #1 on: June 11, 2018, 08:19:33 am »
What's your build command for your application?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

jamesl22

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Hidden symbols when static linking
« Reply #2 on: June 11, 2018, 08:59:19 am »
Code: [Select]
Step 52/52 : RUN make KERNELCXXFLAGS="-DSFML_STATIC -I`pwd`/src/kernel"
 ---> Running in ba0b5eceb2be
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/blockchain.cpp -o src/kernel/blockchain.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/blockchaintypes.cpp -o src/kernel/blockchaintypes.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/math.cpp -o src/kernel/math.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/storage.cpp -o src/kernel/storage.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/network.cpp -o src/kernel/network.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/networkpeer.cpp -o src/kernel/networkpeer.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/base64.cpp -osrc/kernel/base64.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/crypto.cpp -osrc/kernel/crypto.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/log.cpp -o src/kernel/log.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/contract.cpp -o src/kernel/contract.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/consensus/AVRR.cpp -o src/kernel/consensus/AVRR.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/consensus/PoW.cpp -o src/kernel/consensus/PoW.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/kernel/merkletree.cpp -o src/kernel/merkletree.cpp.o
gcc -fPIC -O3 -c src/kernel/consensus/Lyra2REv2/Lyra2RE.c -o src/kernel/consensus/Lyra2REv2/Lyra2RE.c.o
gcc -fPIC -O3 -c src/kernel/consensus/Lyra2REv2/Lyra2.c -o src/kernel/consensus/Lyra2REv2/Lyra2.c.o
gcc -fPIC -O3 -c src/kernel/consensus/Lyra2REv2/Sponge.c -o src/kernel/consensus/Lyra2REv2/Sponge.c.o
gcc -fPIC -O3 -c src/kernel/consensus/Lyra2REv2/sha3/blake.c -o src/kernel/consensus/Lyra2REv2/sha3/blake.c.o
gcc -fPIC -O3 -c src/kernel/consensus/Lyra2REv2/sha3/cubehash.c -o src/kernel/consensus/Lyra2REv2/sha3/cubehash.c.o
gcc -fPIC -O3 -c src/kernel/consensus/Lyra2REv2/sha3/keccak.c -o src/kernel/consensus/Lyra2REv2/sha3/keccak.c.o
gcc -fPIC -O3 -c src/kernel/consensus/Lyra2REv2/sha3/skein.c -o src/kernel/consensus/Lyra2REv2/sha3/skein.c.o
gcc -fPIC -O3 -c src/kernel/consensus/Lyra2REv2/sha3/bmw.c -o src/kernel/consensus/Lyra2REv2/sha3/bmw.c.o
g++ -shared -L/usr/lib src/kernel/blockchain.cpp.o src/kernel/blockchaintypes.cpp.o src/kernel/math.cpp.o src/kernel/storage.cpp.o src/kernel/network.cpp.o src/kernel/networkpeer.cpp.o src/kernel/base64.cpp.o src/kernel/crypto.cpp.o src/kernel/log.cpp.o src/kernel/contract.cpp.o src/kernel/consensus/AVRR.cpp.o src/kernel/consensus/PoW.cpp.o src/kernel/merkletree.cpp.o src/kernel/consensus/Lyra2REv2/Lyra2RE.c.o src/kernel/consensus/Lyra2REv2/Lyra2.c.o src/kernel/consensus/Lyra2REv2/Sponge.c.o src/kernel/consensus/Lyra2REv2/sha3/blake.c.o src/kernel/consensus/Lyra2REv2/sha3/cubehash.c.o src/kernel/consensus/Lyra2REv2/sha3/keccak.c.o src/kernel/consensus/Lyra2REv2/sha3/skein.c.o src/kernel/consensus/Lyra2REv2/sha3/bmw.c.o -o libck.so
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/client/main.cpp -o src/client/main.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/client/rpcserver.cpp-o src/client/rpcserver.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/client/wallet.cpp -osrc/client/wallet.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/client/httpserver.cpp -o src/client/httpserver.cpp.o
g++ -DSFML_STATIC -I/cryptokernel/src/kernel -fPIC -I/usr/include/lua5.3 -c src/client/multicoin.cpp-o src/client/multicoin.cpp.o
g++ src/client/main.cpp.o src/client/rpcserver.cpp.o src/client/wallet.cpp.o src/client/httpserver.cpp.o src/client/multicoin.cpp.o -o ckd -L/usr/lib -I. -L. -L/usr/local/lib -Wl,-rpath -Wl,./ -lck -llua5.3 -lcrypto -ldl -pthread -lleveldb -lmicrohttpd -ljsonrpccpp-common -ljsonrpccpp-server -ljsonrpccpp-client -lcurl -lgcov -ljsoncpp -lsfml-network -lsfml-system
/usr/local/lib/liblua5.3.a(loslib.o): In function `os_tmpname':
loslib.c:(.text+0x2b0): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
/usr/bin/x86_64-linux-gnu-ld: ckd: hidden symbol `_ZN2sf9IpAddress15getLocalAddressEv' in /usr/local/lib/libsfml-network.a(IpAddress.cpp.o) is referenced by DSO
/usr/bin/x86_64-linux-gnu-ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Makefile:92: recipe for target 'ckd' failed
make: *** [ckd] Error 1
The command '/bin/sh -c make KERNELCXXFLAGS="-DSFML_STATIC -I`pwd`/src/kernel"' returned a non-zero code: 2

I can give you a Dockerfile so you can reproduce it exactly if that helps you.
« Last Edit: June 11, 2018, 09:01:34 am by jamesl22 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Hidden symbols when static linking
« Reply #3 on: June 11, 2018, 09:32:08 am »
I'm not sure, what I would try is to link SFML before the other libraries.

Also since the error mentions your shared library ckd, do you use SFML there as well?
And why do you want to link SFML statically, yet you build your own library shared?
Personally, I'd just go full on static or full on shared, as mixing will often lead to duplicated symbols in certain cases.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

jamesl22

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Hidden symbols when static linking
« Reply #4 on: June 11, 2018, 08:39:45 pm »
Changing the linking order unfortunately did not help. As you suggested, building the ckd binary without the libck dynamic library makes it build successfully:

Code: [Select]
g++ src/client/main.cpp.o src/client/rpcserver.cpp.o src/client/wallet.cpp.o src/client/httpserver.cpp.o src/client/multicoin.cpp.o src/kernel/blockchain.cpp.o src/kernel/blockchaintypes.cpp.o src/kernel/math.cpp.o src/kernel/storage.cpp.o src/kernel/network.cpp.o src/kernel/networkpeer.cpp.o src/kernel/base64.cpp.o src/kernel/crypto.cpp.o src/kernel/log.cpp.o src/kernel/contract.cpp.o src/kernel/consensus/AVRR.cpp.o src/kernel/consensus/PoW.cpp.o src/kernel/merkletree.cpp.o src/kernel/consensus/regtest.cpp.o src/kernel/consensus/Lyra2REv2/Lyra2RE.c.o src/kernel/consensus/Lyra2REv2/Lyra2.c.o src/kernel/consensus/Lyra2REv2/Sponge.c.o src/kernel/consensus/Lyra2REv2/sha3/blake.c.o src/kernel/consensus/Lyra2REv2/sha3/cubehash.c.o src/kernel/consensus/Lyra2REv2/sha3/keccak.c.o src/kernel/consensus/Lyra2REv2/sha3/skein.c.o src/kernel/consensus/Lyra2REv2/sha3/bmw.c.o -o ckd -L/usr/lib -I. -L. -L/usr/local/lib -Wl,-rpath -Wl,./ -lsfml-network -lsfml-system -llua5.3 -lcrypto -ldl -pthread -lleveldb -lmicrohttpd -ljsonrpccpp-common -ljsonrpccpp-server -ljsonrpccpp-client -lcurl -lgcov -ljsoncpp
/usr/local/lib/liblua5.3.a(loslib.o): In function `os_tmpname':
loslib.c:(.text+0x2b0): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
Removing intermediate container 983225e60510
 ---> 5346ce542187
Successfully built 5346ce542187

I am still curious though why I cannot statically link SFML with my dynamic libck library. The motivation being that libck is distinct from ckd and could even be seperate repos in the future.