majintao0131 / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

library cannot link on 64 bit architectures with shared objects #44

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Link on a 64 Bit Machine against a shared object

What is the expected output? What do you see instead?
It won't compile with the following warning: 
{{{
/usr/bin/ld:
/home/tfoote/stable/work/common/yaml-cpp/yaml-cpp/lib/libyaml-cpp.a(emitter.cpp.
o):
relocation R_X86_64_32 against `a local symbol' can not be used when making
a shared object; recompile with -fPIC
}}}

What version of the product are you using? On what operating system?
r265 on Ubuntu Jaunty 64 bit

Please provide any additional information below.
The problem is that on 64 bit architectures to link a static library
against a shared library it must have -fPIC declared.  CMake adds -fPIC to
64 bit shared libraries automatically.  There are two fixes.  One is to add
-fPIC to the compile flags for the static lib automatically.  The other is
to make it a shared object, for which CMake will automatically add -fPIC on
64 bit architectures.  

The preferred approach is to make the library a shared object.  The patch
for that is in shared.patch.  

The alternative is to add -fPIC manually to the static library.  The patch
for that is in fPIC.patch.  

If you have any questions I'm watching this issue.  

Original issue reported on code.google.com by Tully.Foote on 17 Sep 2009 at 7:14

Attachments:

GoogleCodeExporter commented 9 years ago
That's weird, since in the CMakeLists.txt file, we have

set(LIB_TYPE SHARED)

and

add_library(yaml-cpp
    ${LIB_TYPE}
    ...
)

so it should be making a shared library. I wasn't 100% sure that this was how 
CMake
variables work, but it seems to work (on all the systems that I tried). Does it 
not
try to build a shared library on yours? Am I doing something wrong here with 
CMake
variables?

Original comment by jbe...@gmail.com on 17 Sep 2009 at 7:22

GoogleCodeExporter commented 9 years ago
That's my fault.  

I originally built the patch against r175 and ported it forward,  I checked 
that it
still worked after I updated, but I didn't check whether you had already fixed 
it.  

My ticket's invalid.  Please close.  

Sorry for the bother.

Original comment by Tully.Foote on 18 Sep 2009 at 12:21

GoogleCodeExporter commented 9 years ago
OK. Thanks for the support.

Original comment by jbe...@gmail.com on 18 Sep 2009 at 12:42

GoogleCodeExporter commented 9 years ago
Sorry, I don't kown how to use these *.patch files. Could you give me some help 
in detail? Thanks. 

Original comment by Kor...@gmail.com on 18 May 2012 at 3:56

GoogleCodeExporter commented 9 years ago
@Komny, if you want to build a shared library, use the instructions on the 
front page.

As Tully.Foote mentioned, the patch fixes an old version of the CMakeLists.txt 
file, so it's not relevant.

In general, to use a patch file, use the command "patch". (Try "man patch" or 
google it for more info.)

Original comment by jbe...@gmail.com on 18 May 2012 at 4:50

GoogleCodeExporter commented 9 years ago
good

Original comment by wangzhiq...@gmail.com on 21 Aug 2012 at 5:49