BitShares Forum

Main => Technical Support => Topic started by: HardFork on February 13, 2014, 10:19:28 pm

Title: build errors
Post by: HardFork on February 13, 2014, 10:19:28 pm
I followed the build instructions.

When I run: make

I get:

../vendor/leveldb-1.12.0/libleveldb.a(port_posix.cc.o): In function `leveldb::port::InitOnce(int*, void (*)())':
/home/tzadik/BitShares/vendor/leveldb-1.12.0/port/port_posix.cc:50: undefined reference to `pthread_once'
Title: Re: build errors
Post by: speedy on February 13, 2014, 11:52:06 pm
Inside /bts_wallet/CMakeLists.txt (or whichever app you are building), you need to add pthread as an argument to target_link_libraries().
Title: Re: build errors
Post by: bytemaster on February 14, 2014, 01:21:35 am
Inside /bts_wallet/CMakeLists.txt (or whichever app you are building), you need to add pthread as an argument to target_link_libraries().

Don't just add pthread, use ${pthread} which is conditionally set on Linux.... submit a pull request and I will merge it.
Title: Re: build errors
Post by: HardFork on February 14, 2014, 01:28:46 am
I tried both pthread and ${pthread} and got the same problem each time.
Title: Re: build errors
Post by: bytemaster on February 14, 2014, 01:50:56 am
I tried both pthread and ${pthread} and got the same problem each time.

Which executable are you attempting to build?
Title: Re: build errors
Post by: HardFork on February 14, 2014, 02:02:56 am
bts_server and bts_wallet
Title: Re: build errors
Post by: bytemaster on February 14, 2014, 02:15:47 am
bts_server and bts_wallet

Link order matters in linux... try putting it at the beginning and end of the lib list.
Title: Re: build errors
Post by: HardFork on February 14, 2014, 03:07:56 am
I tried both beginning and ending and i'm still getting the same problem.

I also ran: make VERBOSE=1 to capture the command that caused the errors:

/usr/bin/c++   -O2 -g -DNDEBUG    CMakeFiles/bts_server.dir/server.cpp.o CMakeFiles/bts_server.dir/chain_connection.cpp.o CMakeFiles/bts_server.dir/chain_server.cpp.o  -o bts_server -rdynamic ../libbshare.a -lrt -ldl ../fc/libfc.a ../fc/vendor/easylzma/src/libeasylzma_static.a -Wl,-Bstatic -lboost_thread-mt -lboost_date_time-mt -lboost_system-mt -lboost_filesystem-mt -lboost_program_options-mt -lboost_signals-mt -lboost_serialization-mt -lboost_chrono-mt -lboost_unit_test_framework-mt -lboost_context-mt -lboost_coroutine -lssl -lcrypto ../vendor/miniupnp/miniupnpc/libminiupnpc.a ../vendor/leveldb-1.12.0/libleveldb.a -Wl,-Bdynamic -ldb_cxx -lz

but the command doesn't even have -lpthread in it, so it doesn't seem like my changing the CMakeLists.txt  had any effect.  I even tried adding -lpthread to the command manually (both at the beginning and end) and that didn't help... still the same error
Title: Re: build errors
Post by: HardFork on February 14, 2014, 03:18:58 am
OK, I finally got past it by using pthread (not ${pthread})

Now I have a new error:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x11): undefined reference to `dlopen'
Title: Re: build errors
Post by: HardFork on February 14, 2014, 03:28:47 am
OK... I had previously added pthread to several CMakeLists.txt files but I wanted to narrow it down, so I removed them all and added them back one by one.

It turns out the only change needed to get past the "undefined reference to `pthread_once'" error was to add the line:

    target_link_libraries( leveldb pthread )

to the end of "BitShares/vendor/leveldb-1.12.0/CMakeLists.txt"

(Previously there was no target_link_libraries at all in that file)
Title: Re: build errors
Post by: bytemaster on February 14, 2014, 03:29:32 am
OK, I finally got past it by using pthread (not ${pthread})

Now I have a new error:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x11): undefined reference to `dlopen'

Add "dl" after pthread.
Title: Re: build errors
Post by: HardFork on February 14, 2014, 03:55:52 am
I already figured out to try that and it didn't work.  (It turns out dl was already there anyway because of ${CMAKE_DL_LIBS} so me adding dl just caused it to appear twice)

I ran: make VERBOSE=1 to find out the command that was failing and if I manually run that /usr/bin/c++ command, adding -ldl at the very end, it succeeds.  So how can we get CMakeLists.txt put dl at the very end of the /usr/bin/c++ command?
Title: Re: build errors
Post by: HardFork on February 14, 2014, 04:00:08 am
Here is the command I ran manually which succeeded:

/usr/bin/c++   -O2 -g -DNDEBUG    CMakeFiles/bts_wallet.dir/main.cpp.o CMakeFiles/bts_wallet.dir/chain_connection.cpp.o  -o bts_wallet -rdynamic ../libbshare.a -lrt -lreadline -ldl ../fc/libfc.a ../fc/vendor/easylzma/src/libeasylzma_static.a -Wl,-Bstatic -lboost_thread-mt -lboost_date_time-mt -lboost_system-mt -lboost_filesystem-mt -lboost_program_options-mt -lboost_signals-mt -lboost_serialization-mt -lboost_chrono-mt -lboost_unit_test_framework-mt -lboost_context-mt -lboost_coroutine -lssl -lcrypto ../vendor/miniupnp/miniupnpc/libminiupnpc.a ../vendor/leveldb-1.12.0/libleveldb.a -Wl,-Bdynamic -lpthread -ldb_cxx -lz -ldl

Note that there is an "-ldl" early in the command (presumably from the ${CMAKE_DL_LIBS} in CMakeLists.txt) and that I had to add "-ldl" again at the end.

Need to get this to happen using only CMakeLists.txt
Title: Re: build errors
Post by: alt on February 14, 2014, 05:18:24 am
I add it at fc/CMakeLists.txt
Code: [Select]
-target_link_libraries( fc easylzma_static ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} )
+target_link_libraries( fc easylzma_static ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${CMAKE_DL_LIBS} )
 
Title: Re: build errors
Post by: HardFork on February 14, 2014, 12:48:58 pm
That doesn't help... my target_link_libraries already has ${CMAKE_DL_LIBS} ... it still fails because -ldl needs to be last in the c++ command line (see my previous post)
Title: Re: build errors
Post by: alt on February 14, 2014, 03:37:37 pm
That doesn't help... my target_link_libraries already has ${CMAKE_DL_LIBS} ... it still fails because -ldl needs to be last in the c++ command line (see my previous post)

try this:
Code: [Select]
diff Bitshares/CMakeLists.txt

--target_link_libraries(bshare fc upnpc-static leveldb ${BDB_LIBRARIES} ${ZLIB_LIBRARIES})
++target_link_libraries(bshare fc upnpc-static leveldb ${BDB_LIBRARIES} ${ZLIB_LIBRARIES}  ${CMAKE_DL_LIBS})
Title: Re: build errors
Post by: HardFork on February 19, 2014, 01:53:28 am
It worked!  Rock on!