LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-03-2018, 06:03 AM   #1
ario
Member
 
Registered: Nov 2010
Posts: 55

Rep: Reputation: 2
Exclamation Force CMake to build shared libraries instead of static


Hi Folks,
I'm up to an opensource library on github named libnode. Compiling it using cmake and make generates a .a file which is static. For my purpose (Running a proprietary software named slack) I need a .so file. The git repository also has many submodules which I also clone to compile it. Tried modifying CMakeLists.txt file to replace:
Code:
add_library(node STATIC
with:
Code:
add_library(node SHARED
But then I get:
Code:
/usr/bin/ld: deps/libj/libj.a(array_list.cpp.o): relocation R_X86_64_PC32 against symbol `_ZTVN4libj6detail17GenericCollectionINS_9ArrayListENS0_5ValueEEE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/node.dir/build.make:587: libnode.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/node.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
Any idea would be highly appreciated. Thanks in advance.
 
Old 12-03-2018, 01:58 PM   #2
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 756

Rep: Reputation: 144Reputation: 144
Quote:
Originally Posted by ario View Post
Code:
... can not be used when making a shared object; recompile with -fPIC
Try adding this after the add_library line:
Code:
set_property(TARGET node PROPERTY POSITION_INDEPENDENT_CODE ON)
Or
Code:
SET_TARGET_PROPERTIES(node PROPERTIES COMPILE_FLAGS "-fPIC")
Though, position independent is supposed to be set by default for static builds, so maybe there's some other error.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackware-current: /usr/share/cmake and /usr/share/cmake-3.3 directories igor29768 Slackware 1 11-07-2015 01:37 AM
CMake: link multiple archives (static libs) into shared library taylor_ma Programming 5 07-12-2012 05:52 AM
CMake Strange "Install" behaviour with home-grown software [Linux x86_64, CMake 2.8] ajschaeffer Programming 0 10-24-2011 04:21 AM
cmake: Using find_package(Boost) when FindBoost.cmake is not in the default location damien_d Programming 3 10-27-2010 04:40 PM
Static libraries vs shared Libraries catallergy Linux - Newbie 2 03-16-2010 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration