Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shared library build on OS X #212

Merged
merged 1 commit into from
Oct 18, 2015
Merged

Conversation

dean0x7d
Copy link
Contributor

I noticed this while trying to run format-benchmark. Building cppformat on OS X with BUILD_SHARED_LIBS=ON results in:

ld: unknown option: --as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libcppformat.1.2.0.dylib] Error 1
make[1]: *** [CMakeFiles/cppformat.dir/all] Error 2
make: *** [all] Error 2

This PR fixes it.

As a side note: The shared lib build is also broken with MSVC and it's a bit more elaborate. I don't think this is a big issue since a shared lib is probably not the optimal way to use cppformat. But just FYI.

This commit will resolve the ignoring unknown flag --as-needed warning on MSVC, but the build will still fail because it needs __declspec(dllexport) and __declspec(dllimport) to know which functions and classes to export. Those need to be behind macro defines and then peppered all over the code which can get quite ugly. Template instantiations can also complicate matters. The code uglification is probably a high price to pay for an almost-never-used feature. I am not advocating for it, but I can take a stab at making it work if there is interest.

@vitaut
Copy link
Contributor

vitaut commented Oct 18, 2015

Thanks for the PR. Wouldn't it be better to check for CMAKE_COMPILER_IS_GNUCXX instead because the issue is probably specific to clang and not OS X?

Regarding the DLL API, I'd rather not introduce it at this point unless there are strong reasons to do so because it will clutter the code.

@dean0x7d
Copy link
Contributor Author

It's a linker flag so it's platform specific. GCC 5.2 (the real one, not the clang alias) on OS X still calls the same ld and fails:

ld: unknown option: --as-needed
collect2: error: ld returned 1 exit status
make[2]: *** [libcppformat.1.2.0.dylib] Error 1
make[1]: *** [CMakeFiles/cppformat.dir/all] Error 2
make: *** [all] Error 2

vitaut added a commit that referenced this pull request Oct 18, 2015
Fix shared library build on OS X
@vitaut vitaut merged commit 5405b09 into fmtlib:master Oct 18, 2015
@vitaut
Copy link
Contributor

vitaut commented Oct 18, 2015

Good point. Too bad CMake doesn't seem to have a method to check for linker flags.

@dean0x7d dean0x7d deleted the fix_shared_lib branch October 18, 2015 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants