I might have used the term incorrectly. The context is that I am trying to build a shared library which, on running by its own will print the version info ie., the name of the shared library will be libmylib.so which can be used to link with and build other executables. But when run as a command libmylib.so will print some information. Whether you call this an executable or a shared object is immaterial. For instance, /lib/libc.so.6 behaves in a similar way. I was just trying to mimic that behavior in my library.
Lakshman. ----- Original Message ---- From: Hendrik Sattler <[email protected]> To: K Lakshman <[email protected]> Cc: [email protected] Sent: Wed, 23 June, 2010 3:59:27 PM Subject: Re: [CMake] CMake - overriding shared linker flags Zitat von K Lakshman <[email protected]>: > I'm trying to build a shared library (gcc on Linux CentOS) with -pie flag. > If >I > simply add the flag -pie to CMAKE_SHARED_LINKER_FLAGS "-Wl,-pie", the command > that gets invoked looks like this: > gcc -shared -Wl,-pie <rest of the command> -o libmylibrary.so > > A shared library built like this is not runnable stand-alone (I get an error > /usr/lib/libc.so: bad ELF interpreter: No such file or directory). Where as > if >I > can get the shared library to be built using this command: > gcc -Wl,-shared -Wl,-pie <rest of the command> -o libmylibrary.so > > then that shared library seems to run fine stand alone. (The only difference > betweent the two commands is that the -shared flags is passed to gcc in the > first version and directly to the linker in the second version thus bypassing > collect2). > > How do I change the shared library build command to use -Wl,-shared instead of > -shared? Do I have to write a complete custom command or can I use some tricks > to simply change this part alone? Does that actually make sense? To cite from gcc manpage: -pie Produce a position independent executable on targets which support it. For predictable results, you must also specify the same set of options that were used to generate code (-fpie, -fPIE, or model suboptions) when you specify this option. -shared Produce a shared object which can then be linked with other objects to form an executable. Not all systems support this option. For predictable results, you must also specify the same set of options that were used to generate code (-fpic, -fPIC, or model suboptions) when you specify this option.[1] So, you should NOT use -pie for shared libraries (which are _already_ position independent) but only for static libraries and executables, if you really want that. Additionally, you then use "gcc -pie", not "gcc -Wl,-pie". HS _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
