Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
how to add -fPIC into cmake ebuild
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
guyuming
Apprentice
Apprentice


Joined: 19 Nov 2020
Posts: 247

PostPosted: Wed Dec 18, 2024 7:58 am    Post subject: how to add -fPIC into cmake ebuild Reply with quote

i am trying to create an ebuild for https://github.com/arangodb/linenoise-ng and reference that library in my code.

when compile my code, i get what follows:

Code:

/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib/liblinenoise.a(linenoise.cpp.o): relocation R_X86_64_PC32 against symbol `stdout@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC


I think i need to add -fPIC into my ebuild for linenoise-ng which inherit cmake.eclass

I tried what follows, but it does not seem to work.

Code:

src_configure() {
        local mycmakeargs=(
                -DCMAKE_CXX_FLAGS_RELEASE="-fPIC"
        )
   cmake_src_configure
}


or
Code:

-DCMAKE_CXX_FLAGS_RELEASE+="-fPIC"
Back to top
View user's profile Send private message
nicop
Tux's lil' helper
Tux's lil' helper


Joined: 10 Apr 2014
Posts: 103

PostPosted: Wed Dec 18, 2024 10:15 am    Post subject: Reply with quote

you can use before cmake_src_configure :
append-cflags -fPIC

it needs inherit flag-o-matic


or something like

-DCMAKE_C_FLAGS_RELEASE="${CFLAGS} -fPIC" ?
Back to top
View user's profile Send private message
bstaletic
Guru
Guru


Joined: 05 Apr 2014
Posts: 402

PostPosted: Wed Dec 18, 2024 12:42 pm    Post subject: Reply with quote

The intended way to turn on position independent code with cmake is
https://cmake.org/cmake/help/latest/variable/CMAKE_POSITION_INDEPENDENT_CODE.html
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1770
Location: South America

PostPosted: Wed Dec 18, 2024 12:45 pm    Post subject: Re: how to add -fPIC into cmake ebuild Reply with quote

guyuming wrote:
Code:
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib/liblinenoise.a(linenoise.cpp.o): relocation R_X86_64_PC32 against symbol `stdout@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC

Is your code going in a shared library? Linenoise Next Generation only provides a static library:

CMakeLists.txt
Code:
# build liblinenoise
add_library(
  linenoise
  STATIC
  src/ConvertUTF.cpp
  src/linenoise.cpp
  src/wcwidth.cpp
)

I'd rather patch CMakeLists.txt in your ebuild to have CMake create a shared library instead.
_________________
NeddySeagoon wrote:
I'm not a witch, I'm a retired electronics engineer :)
Ionen wrote:
As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum