jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
5.18k stars 1.87k forks source link

master - linking error on aarm64 #518

Open oxoocoffee opened 7 years ago

oxoocoffee commented 7 years ago

Hello,

I just cloned latest main and did try to cross-compile to aarm64. I used main since I do not have boost. Thank you guys for dropping boost :) Yaml-cpp built was fine and it produced static lib. After installing to to my sys root I did try to compile my application. My application did build just fine before I added yaml support.Whe I am trying to link my application with yaml static libI get this error

aarch64-gnu-linux/../../libexec/aarch64-gnu-linux/gcc/aarch64-gnu-linux/4.9.2/ld: /opt/cross-arm/sysroot/usr/local/lib/libyaml-cpp.a(convert.cpp.o)(.text+0xcc): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `_ZNSs4_Rep20_S_empty_rep_storageE@@GLIBCXX_3.4'

../libexec/aarch64-gnu-linux/gcc/aarch64-gnu-linux/4.9.2/ld: final link failed: Nonrepresentable section on output

Compiler version used to cross compile: aarch64-gnu-linux-g++ --version aarch64-gnu-linux-g++ (GCC) 4.9.2

My project by default build and links to dynamic libs. I did try to add -Bstatic libyaml-cpp.a -Bdynamic to my make but did not work. After rebuilding yaml-cpp -DBUILD_SHARED_LIBS=ON everything worked fine.

https://reverseengineering.stackexchange.com/questions/10722/what-is-s-empty-rep-storage-used-for-in-this-code

StefanTheWiz commented 7 years ago

you need to

I'm planning to rewrite YAML_CPP_API as YAML_CPP_EXPORT for classes and YAML_CPP_EXTERN for functions etc. The new macros would use the appropriate key word depending on whether you're building as a DLL or as a static lib. Could do a pull request when done, if there's a need for that.

oxoocoffee commented 7 years ago

Thinking about adding this first. Which top H file is good place to do so? dll.h?

if defined(_MSC_VER)

//  Microsoft 
#define YAML_CPP_EXPORT __declspec(dllexport)
#define YAML_CPP_IMPORT __declspec(dllimport)

elif defined(GNUC)

//  GCC
#define YAML_CPP_EXPORT __attribute__((visibility("default")))
#define YAML_CPP_IMPORT

else

#define YAML_CPP_EXPORT
#define YAML_CPP_IMPORT
#pragma warning Unknown dynamic link import/export semantics.

endif

StefanTheWiz commented 7 years ago

yes, dll.h

IanEmmons commented 4 years ago

oxoocoffee's solution is the correct direction, now that GCC (and clang/llvm) have gone to hidden symbols by default.