Skip to content
This repository was archived by the owner on Apr 21, 2018. It is now read-only.

Clang static linking #15

Closed
wants to merge 4 commits into from
Closed

Clang static linking #15

wants to merge 4 commits into from

Conversation

ctrueden
Copy link
Contributor

On OS X 10.9 Mavericks, LLVM with clang is now used. This branch adds case logic to the GppLinker implementation to handle clang's incompatibilities with gcc, notably the unsupported -static-libgcc and -shared-libgcc flags.

I am far from a C++ expert, so would appreciate code review here. In particular, I suspect that simply suppressing the -lstdc++-static flag is the wrong solution. (10.9 also uses libc++ instead of libstdc++ now; but -lc++-static also doesn't work...)

Note that the first three commits are merely to support the new isClang() method of GppLinker, which needs to call out to g++ --version to check that. The CaptureStreamHandler previously had an annoying limitation where CaptureStreamHandler.run would return only stderr if it was nonempty—and g++ --version happens to return a mixture of stderr and stdout. So now the execute method provides a way to request stdout specifically, which is what we need here.

The previous logic always threw away stdout if anything was present on
stderr. But we sometimes need the contents of stdout despite there also
being a nonempty stderr.

For backwards compatibility, this change leaves the behavior of
getOutput() alone, while adding getStdout() and getStderr() methods for
situations when more specifics are necessary.
This method provides a way to easily execute a command while returning
the CaptureStreamHandler that was used to capture the output. This
provides a more flexible alternative to CaptureStreamHandler#run, which
returns only stderr or stdout contingent on whether stderr is nonempty.

Unfortunately, that mechanism left no way to interrogate stdout in the
case of a nonempty stderr. In contrast to run, The execute method
returns the CaptureStreamHandler itself, so that both stderr and stdout
can be freely accessed.
OS X 10.9 Mavericks now uses LLVM with clang by default. While it
pretends to be gcc, there are a few incompatibilities. In particular,
the -static-libgcc and -shared-libgcc flags are unsupported, and
-lstdc++-static does not work because that static library is not
present on standard include paths.
@buildhive
Copy link

NAR plugin for Maven » cpptasks-parallel #9 SUCCESS
This pull request looks good
(what's this?)

@ctrueden
Copy link
Contributor Author

We almost certainly need PR #14 first, and then some additional changes to the clang configuration, rather than the hacky solution of this PR. Anyone else less clueless about cpptasks-parallel care to comment?

@dscho
Copy link
Member

dscho commented Nov 23, 2013

DEV@cloud: Can one of the admins verify this patch?

@dscho
Copy link
Member

dscho commented Nov 25, 2013

Well, it seems that your approach was pretty good and my suggestion was not so. Could you please have a look at https://github.com/maven-nar/cpptasks-parallel/compare/clang and tell me whether that is okay...?

@dscho
Copy link
Member

dscho commented Nov 26, 2013

@ctrueden did you have a chance to test yet?

@ctrueden
Copy link
Contributor Author

It "works" (i.e., BUILD SUCCESS) but as I feared, the resultant library is not actually statically linked with libc++. Unfortunately, it seems that there is no static libc++ library on an OS X Mavericks system. At least, I couldn't find one by searching with find / -name 'libc++*' and find /usr/lib -name '*.a'. And no one on SO seems to have the answer, either (e.g., 19649634), except to comment that there is no static libc on OS X.

So I vote that we simply punt: issue a warning stating that the resultant binary will not actually be statically linked in this circumstance, and keep my hack above since it at least makes the build succeed.

@ctrueden
Copy link
Contributor Author

Closing in favor of PR #16, which is a rebased combination of this PR and #14.

@ctrueden ctrueden closed this Nov 26, 2013
@ctrueden ctrueden deleted the clang-static-linking branch April 20, 2015 20:51
@kangyz
Copy link

kangyz commented Jun 1, 2016

Caused by: D:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\cl failed with return code 2
at com.github.maven_nar.cpptasks.compiler.CommandLineCompiler.compile(CommandLineCompiler.java:257)
at com.github.maven_nar.cpptasks.compiler.CommandLineCompilerConfiguration.compile(CommandLineCompilerConfiguration.java:166)
at com.github.maven_nar.cpptasks.CCTask$Core.run(CCTask.java:108)

Anyone knows how to solve the problem?

@ctrueden
Copy link
Contributor Author

ctrueden commented Jun 5, 2016

@kangyz Shouldn't you be posting this as a new issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants