Re: [CMake] How to specify -fpic ?

2010-09-30 Thread David Aldrich
Hi Michael

Thanks for your reply.

 The only difference between -fpic and -fPIC is that the latter has no limit
 on the size of the global offsets table and this is only relevant for the
 m68k, PowerPC and SPARC architectures (according to the GCC manual page). 

Yes, we aren't using those architectures.

 Are you using -fvisibility=hidden somewhere?

No.

 Is this option the only difference of the link commands?

Actually, the shared library linker commands are similar but the executable 
linker commands are quite different.

CMake:

/usr/bin/c++ -O3 -DNDEBUG -Wall -m64 -o myProj -rdynamic Kernel/libKernel.a 
-lpython2.4

Manual make:

g++ -o myProj -ldl -Wl,-whole-archive,-export-dynamic ../Kernel/libKernel.a  
-lboost_python-mt -lpython2.4 -Wl,--no-whole-archive

I will have to analyse these flags. Any thoughts on the use of 
-whole-archive/--no-whole-archive here please?

BR

David


___
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


Re: [CMake] How to specify -fpic ?

2010-09-30 Thread Marcel Loose
On Thu, 2010-09-30 at 10:15 +0100, David Aldrich wrote:
 Hi Michael
 
 Thanks for your reply.
 
  The only difference between -fpic and -fPIC is that the latter has
no limit
  on the size of the global offsets table and this is only relevant
for the
  m68k, PowerPC and SPARC architectures (according to the GCC manual
page). 
 
 Yes, we aren't using those architectures.
 
  Are you using -fvisibility=hidden somewhere?
 
 No.
 
  Is this option the only difference of the link commands?
 
 Actually, the shared library linker commands are similar but the
executable linker commands are quite different.
 
 CMake:
 
 /usr/bin/c++ -O3 -DNDEBUG -Wall -m64 -o myProj -rdynamic
Kernel/libKernel.a -lpython2.4
 
 Manual make:
 
 g++ -o myProj -ldl -Wl,-whole-archive,-export-dynamic
../Kernel/libKernel.a  -lboost_python-mt -lpython2.4
-Wl,--no-whole-archive
 
 I will have to analyse these flags. Any thoughts on the use of
-whole-archive/--no-whole-archive here please?
 
 BR
 
 David

See this yesterday's mail:
http://www.mail-archive.com/cmake@cmake.org/msg31781.html

HTH,
Marcel Loose.


___
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


Re: [CMake] How to specify -fpic ?

2010-09-30 Thread Michael Wild

On 30. Sep, 2010, at 11:15 , David Aldrich wrote:

 Hi Michael
 
 Thanks for your reply.
 
 The only difference between -fpic and -fPIC is that the latter has no limit
 on the size of the global offsets table and this is only relevant for the
 m68k, PowerPC and SPARC architectures (according to the GCC manual page). 
 
 Yes, we aren't using those architectures.
 
 Are you using -fvisibility=hidden somewhere?
 
 No.
 
 Is this option the only difference of the link commands?
 
 Actually, the shared library linker commands are similar but the executable 
 linker commands are quite different.
 
 CMake:
 
 /usr/bin/c++ -O3 -DNDEBUG -Wall -m64 -o myProj -rdynamic Kernel/libKernel.a 
 -lpython2.4
 
 Manual make:
 
 g++ -o myProj -ldl -Wl,-whole-archive,-export-dynamic ../Kernel/libKernel.a  
 -lboost_python-mt -lpython2.4 -Wl,--no-whole-archive
 
 I will have to analyse these flags. Any thoughts on the use of 
 -whole-archive/--no-whole-archive here please?
 
 BR
 
 David

For one, you are missing -ldl. Add ${CMAKE_DL_LIBS} to your 
target_link_libraries call. The -whole-archive flag is pretty useless with 
executables (unless, you plan to use it as a library too, but that is 
outlandish). --export-dynamic may be also necessary, if your dlopen'ed 
libraries use symbols in your executable.

Michael

--
There is always a well-known solution to every human problem -- neat, 
plausible, and wrong.
H. L. Mencken



PGP.sig
Description: This is a digitally signed message part
___
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

Re: [CMake] How to specify -fpic ?

2010-09-30 Thread David Aldrich
Hi Michael
 
 For one, you are missing -ldl. Add ${CMAKE_DL_LIBS} to your
 target_link_libraries call. 

Thanks for pointing that out. It's in there now:

/usr/bin/c++ -O3 -DNDEBUG -Wall -m64 -o myProj -rdynamic Kernel/libKernel.a 
-ldl -lpython2.4

 --export-dynamic may be also necessary, if your dlopen'ed
 libraries use symbols in your executable.

I tried adding:

SET(CMAKE_EXE_EXPORTS_CXX_FLAG -Wl,--export-dynamic)

But that made no difference to the link command. Am I doing the right thing?

David
___
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


Re: [CMake] How to specify -fpic ?

2010-09-30 Thread David Aldrich
Hi

 I tried adding:
 
 SET(CMAKE_EXE_EXPORTS_CXX_FLAG -Wl,--export-dynamic)
 
 But that made no difference to the link command. Am I doing the right thing?

Fixed this by doing:

SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS )
...
SET_TARGET_PROPERTIES(zodiac PROPERTIES ENABLE_EXPORTS ON)

I now have:

/usr/bin/c++   -O3 -DNDEBUG -Wall -m64  -Wl,--export-dynamic   -o myProj  
Kernel/libKernel.a -ldl -lpython2.4

But I still have the shared library load error.

So now I need to try implementing -whole-archive/--no-whole-archive to see if 
that makes a difference.

Any hints how to do this please?

David

___
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


Re: [CMake] How to specify -fpic ?

2010-09-30 Thread David Aldrich
Hi

Ok, by following the link to the wiki suggested by Michael Loose, I used:

target_link_libraries( myProj -Wl,-whole-archive Kernel -Wl,-no-whole-archive)

This has fixed my problem. The executable links and runs correctly.

My link command is now:

/usr/bin/c++   -O3 -DNDEBUG -Wall -m64  -Wl,--export-dynamic   -o myProj 
-Wl,-whole-archive Kernel/libKernel.a -Wl,-no-whole-archive -ldl -lpython2.4

I don't need portability so I think this is ok.

Michael Wild wrote:

 The -whole-archive flag is pretty useless with executables 
 (unless, you plan to use it as a library too, but that is 
 outlandish). --export-dynamic may be also necessary, if 
 your dlopen'ed libraries use symbols in your executable.

So my concern is now: am I being 'outlandish' ?  The dlopen'ed libraries do use 
functions in libKernel.a that is linked to the executable. Is this outlandish? 
Is there a better way?

Thanks for your help so far.

Best regards 

David 
___
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


Re: [CMake] How to specify -fpic ?

2010-09-30 Thread Michael Wild

On 30. Sep, 2010, at 13:05 , David Aldrich wrote:

 Hi
 
 Ok, by following the link to the wiki suggested by Michael Loose, I used:
 
 target_link_libraries( myProj -Wl,-whole-archive Kernel -Wl,-no-whole-archive)
 
 This has fixed my problem. The executable links and runs correctly.
 
 My link command is now:
 
 /usr/bin/c++   -O3 -DNDEBUG -Wall -m64  -Wl,--export-dynamic   -o myProj 
 -Wl,-whole-archive Kernel/libKernel.a -Wl,-no-whole-archive -ldl -lpython2.4
 
 I don't need portability so I think this is ok.
 
 Michael Wild wrote:
 
 The -whole-archive flag is pretty useless with executables 
 (unless, you plan to use it as a library too, but that is 
 outlandish). --export-dynamic may be also necessary, if 
 your dlopen'ed libraries use symbols in your executable.
 
 So my concern is now: am I being 'outlandish' ?  The dlopen'ed libraries do 
 use functions in libKernel.a that is linked to the executable. Is this 
 outlandish? Is there a better way?

The outlandish referred to using an executable also as a library, so you're 
fine :-) But I think I found the reason for why you need this -whole-archive 
flag: Since your executable doesn't use all of the functions in the Kernel 
library, the linker throws them away. This results in your dlopen'ed functions 
to fail.

So, the options are:

- use -whole-archive as you do now
- make the Kernel library shared
- link the dlopen'ed libraries against Kernel

Michael




PGP.sig
Description: This is a digitally signed message part
___
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

Re: [CMake] How to specify -fpic ?

2010-09-30 Thread David Aldrich
Hi Michael

 So, the options are:
 
 - use -whole-archive as you do now
 - make the Kernel library shared
 - link the dlopen'ed libraries against Kernel

Thanks very much - I understand. I think I will keep the -whole-archive method.

However, now I'm worried about how I link in the Python library:

/usr/bin/c++ -O3 -DNDEBUG -Wall -m64 -o myProj -rdynamic -Wl,-whole-archive 
Kernel/libKernel.a -Wl,-no-whole-archive -ldl -lpython2.4

The dlopen'ed libraries may use the Python library. I guess I could include it 
in the -whole-archive part, but perhaps it would be better to link each shared 
library against Python. Would you agree?

Sorry that I am now off topic w.r.t cmake.

By the way, I think I am pretty much there with changing our build system from 
manually coded makefiles to cmake. I like cmake!  Thanks for all your help in 
getting there.  The support on this list is excellent.

Best regards 

David 

 -Original Message-
 From: Michael Wild [mailto:them...@gmail.com]
 Sent: 30 September 2010 12:20
 To: David Aldrich
 Cc: cmake@cmake.org
 Subject: Re: [CMake] How to specify -fpic ?
 
 
 On 30. Sep, 2010, at 13:05 , David Aldrich wrote:
 
  Hi
 
  Ok, by following the link to the wiki suggested by Michael Loose, I used:
 
  target_link_libraries( myProj -Wl,-whole-archive Kernel
  -Wl,-no-whole-archive)
 
  This has fixed my problem. The executable links and runs correctly.
 
  My link command is now:
 
  /usr/bin/c++   -O3 -DNDEBUG -Wall -m64  -Wl,--export-dynamic   -o myProj -
 Wl,-whole-archive Kernel/libKernel.a -Wl,-no-whole-archive -ldl -lpython2.4
 
  I don't need portability so I think this is ok.
 
  Michael Wild wrote:
 
  The -whole-archive flag is pretty useless with executables (unless,
  you plan to use it as a library too, but that is outlandish).
  --export-dynamic may be also necessary, if your dlopen'ed libraries
  use symbols in your executable.
 
  So my concern is now: am I being 'outlandish' ?  The dlopen'ed libraries do
 use functions in libKernel.a that is linked to the executable. Is this
 outlandish? Is there a better way?
 
 The outlandish referred to using an executable also as a library, so you're
 fine :-) But I think I found the reason for why you need this -whole-archive
 flag: Since your executable doesn't use all of the functions in the Kernel
 library, the linker throws them away. This results in your dlopen'ed
 functions to fail.
 
 So, the options are:
 
 - use -whole-archive as you do now
 - make the Kernel library shared
 - link the dlopen'ed libraries against Kernel
 
 Michael
 

___
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


Re: [CMake] How to specify -fpic ?

2010-09-30 Thread Michael Wild
On 30. Sep, 2010, at 13:30 , David Aldrich wrote:

 Hi Michael
 
 So, the options are:
 
 - use -whole-archive as you do now
 - make the Kernel library shared
 - link the dlopen'ed libraries against Kernel
 
 Thanks very much - I understand. I think I will keep the -whole-archive 
 method.
 
 However, now I'm worried about how I link in the Python library:
 
 /usr/bin/c++ -O3 -DNDEBUG -Wall -m64 -o myProj -rdynamic -Wl,-whole-archive 
 Kernel/libKernel.a -Wl,-no-whole-archive -ldl -lpython2.4
 
 The dlopen'ed libraries may use the Python library. I guess I could include 
 it in the -whole-archive part, but perhaps it would be better to link each 
 shared library against Python. Would you agree?
 

Unless the python library is static (which it AFAIK almost never is) you should 
be safe.

 Sorry that I am now off topic w.r.t cmake.
 
 By the way, I think I am pretty much there with changing our build system 
 from manually coded makefiles to cmake. I like cmake!  Thanks for all your 
 help in getting there.  The support on this list is excellent.

;-) well, CMake does have its quirks and dark corners, but in general I find it 
to be much preferable over anything else I've ever seen so far...

Michael

 
 Best regards 
 
 David 
 
 -Original Message-
 From: Michael Wild [mailto:them...@gmail.com]
 Sent: 30 September 2010 12:20
 To: David Aldrich
 Cc: cmake@cmake.org
 Subject: Re: [CMake] How to specify -fpic ?
 
 
 On 30. Sep, 2010, at 13:05 , David Aldrich wrote:
 
 Hi
 
 Ok, by following the link to the wiki suggested by Michael Loose, I used:
 
 target_link_libraries( myProj -Wl,-whole-archive Kernel
 -Wl,-no-whole-archive)
 
 This has fixed my problem. The executable links and runs correctly.
 
 My link command is now:
 
 /usr/bin/c++   -O3 -DNDEBUG -Wall -m64  -Wl,--export-dynamic   -o myProj -
 Wl,-whole-archive Kernel/libKernel.a -Wl,-no-whole-archive -ldl -lpython2.4
 
 I don't need portability so I think this is ok.
 
 Michael Wild wrote:
 
 The -whole-archive flag is pretty useless with executables (unless,
 you plan to use it as a library too, but that is outlandish).
 --export-dynamic may be also necessary, if your dlopen'ed libraries
 use symbols in your executable.
 
 So my concern is now: am I being 'outlandish' ?  The dlopen'ed libraries do
 use functions in libKernel.a that is linked to the executable. Is this
 outlandish? Is there a better way?
 
 The outlandish referred to using an executable also as a library, so you're
 fine :-) But I think I found the reason for why you need this -whole-archive
 flag: Since your executable doesn't use all of the functions in the Kernel
 library, the linker throws them away. This results in your dlopen'ed
 functions to fail.
 
 So, the options are:
 
 - use -whole-archive as you do now
 - make the Kernel library shared
 - link the dlopen'ed libraries against Kernel
 
 Michael
 
 

--
There is always a well-known solution to every human problem -- neat, 
plausible, and wrong.
H. L. Mencken



PGP.sig
Description: This is a digitally signed message part
___
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

Re: [CMake] How to specify -fpic ?

2010-09-30 Thread Marcel Loose
On Thu, 2010-09-30 at 12:30 +0100, David Aldrich wrote:
 Hi Michael
 
  So, the options are:
  
  - use -whole-archive as you do now
  - make the Kernel library shared
  - link the dlopen'ed libraries against Kernel
 
 Thanks very much - I understand. I think I will keep the
-whole-archive method.
 
 However, now I'm worried about how I link in the Python library:
 
 /usr/bin/c++ -O3 -DNDEBUG -Wall -m64 -o myProj -rdynamic
-Wl,-whole-archive Kernel/libKernel.a -Wl,-no-whole-archive -ldl
-lpython2.4
 
 The dlopen'ed libraries may use the Python library. I guess I could
include it in the -whole-archive part, but perhaps it would be better to
link each shared library against Python. Would you agree?
 
 Sorry that I am now off topic w.r.t cmake.
 
 By the way, I think I am pretty much there with changing our build
system from manually coded makefiles to cmake. I like cmake!  Thanks for
all your help in getting there.  The support on this list is excellent.
 
 Best regards 
 
 David 
 
Hi David,

Considering all the hassle you have to go through. Why don't you build a
shared libKernel.so library and let the runtime loader fix all the
issues you're now trying to solve compile/link time?

Best regards,
Marcel Loose.

___
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


Re: [CMake] How to specify -fpic ?

2010-09-30 Thread David Aldrich
Hi Marcel

 Considering all the hassle you have to go through. Why don't you build a
 shared libKernel.so library and let the runtime loader fix all the
 issues you're now trying to solve compile/link time?

Thanks for your suggestion. I'm not sure how that would work out. At start-up 
the runtime linker would only need to resolve issues between main.cpp, 
libKernel.so and libPython.so. Later I will dlopen some more libraries that 
need libKernel. Would the runtime linker handle that?

BR

David
___
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


Re: [CMake] How to specify -fpic ?

2010-09-29 Thread Michael Hertling
On 09/29/2010 06:25 PM, David Aldrich wrote:
 Hi
 
 My C++ code consists of an executable and several shared libraries.
 
 With my CMake build files, I find that the executable fails to load the 
 shared libraries ( the dlopen() call results in error 'undefined symbol...' ).
 
 The software works fine under our production build system that uses manually 
 coded makefiles.
 
 I notice that the production system linker command invokes -fpic, while CMake 
 uses -fPIC. I am wondering if that is the reason.
 
 I set the compile flags with:
 
 set( CMAKE_CXX_FLAGS_RELEASE -O3 -DNDEBUG -Wall -m64 )
 
 How can I replace -fPIC with -fpic in CMake please?

STRING(REGEX REPLACE -fPIC -fpic CMAKE_SHARED_LIBRARY_CXX_FLAGS
${CMAKE_SHARED_LIBRARY_CXX_FLAGS})

Is this option the only difference of the link commands? Do the compile
commands differ, too? Are there any options in the compile commands
which should also be present in the link commands but are missing?

Regards,

Michael
___
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