Skip to content

fix missing library on BSD systems - #147

Merged
wjakob merged 3 commits into
wjakob:masterfrom
tony:libc++abi-fix
Oct 28, 2016
Merged

fix missing library on BSD systems#147
wjakob merged 3 commits into
wjakob:masterfrom
tony:libc++abi-fix

Conversation

@tony

@tony tony commented Oct 15, 2016

Copy link
Copy Markdown
Contributor

On FreeBSD (haven't tried Linux yet) this library will be missing. I believe it's only available on OS X.

http://libcxxabi.llvm.org/

@tony tony changed the title fix missing library on non-OS X systems fix missing library on BSD systems Oct 21, 2016
@tony

tony commented Oct 21, 2016

Copy link
Copy Markdown
Contributor Author

Builds work in Linux, so this seems to be freebsd only.

I'm going to also test this on openbsd as well for good measure.

@tony

tony commented Oct 22, 2016

Copy link
Copy Markdown
Contributor Author

OpenBSD 6.0

screen shot 2016-10-22 at 1 41 00 am

Let me brush up tomorrow and test across OpenBSD 6.0, FreeBSD 11-STABLE, MacOS and Ubuntu 16.10

@wjakob

wjakob commented Oct 22, 2016

Copy link
Copy Markdown
Owner

Hi @tony,

this looks great. One note: I've found that "-lc++abi" is needed on Linux (when using Clang), and your patch removes it for that platform.

Let me know when this is ready to merge.

Best,
Wenzel

@tony
tony force-pushed the libc++abi-fix branch 2 times, most recently from 8a8ed6a to 9076996 Compare October 23, 2016 18:49
@tony

tony commented Oct 23, 2016

Copy link
Copy Markdown
Contributor Author

Hi @wjakob. I've tested on OpenBSD 6.0, FreeBSD 11-CURRENT, OS X, however have had issues with testing on Ubuntu. It does compile and link correctly on Ubuntu 16.10, but not run due to lack of OpenGL 3.3 support in VirtualBox.

@wjakob

wjakob commented Oct 24, 2016

Copy link
Copy Markdown
Owner

Hi @tony,

this looks great now. No worries about Ubuntu, I am using that frequently myself and everything works fine.

One quick question after looking at the PR once more: I saw that you actually completely disabled libc++ when using Clang as a compiler on *BSD. Is that really the right thing to do? To my knowledge, when using Clang, you'll generally want to combine it with libc++ that was developed specifically to be used with that compiler.

I've run into many incompatibilities in the alternative libstdc++ / Clang combination on Linux, hence this setting in the CMake script.

Best,
Wenzel

@wjakob

wjakob commented Oct 24, 2016

Copy link
Copy Markdown
Owner

(note that this comment is unrelated to the -lc++abi flag which indeed does not seem to be supported on *BSD)

@tony

tony commented Oct 24, 2016

Copy link
Copy Markdown
Contributor Author

FreeBSD 11-STABLE will say cc: warning: argument unused during compilation: '-stdlib=libc++' as a warning. https://lists.freebsd.org/pipermail/freebsd-bugs/2013-October/054196.html

So I can add it back, but we'll get the warning. I have to check OpenBSD again.

I saw that you actually completely disabled libc++ when using Clang as a compiler on *BSD. Is that really the right thing to do? To my knowledge, when using Clang, you'll generally want to combine it with libc++ that was developed specifically to be used with that compiler.

I'm not 100% sure. I omit including libc++ by hand on OpenBSD and FreeBSD (as in my current patch), then how is it building and running on FreeBSD and OpenBSD?

I know CMake does some magic when it comes to adding flags on your behalf. I can't think of a time I've had the need to go in and add the standard lib stuff manually.

libc++abi-build.txt is my cmake --system-information output.

@wjakob

wjakob commented Oct 25, 2016

Copy link
Copy Markdown
Owner

Is this OpenBSD cc actually Clang?

@tony

tony commented Oct 25, 2016

Copy link
Copy Markdown
Contributor Author

Default compiler on OpenBSD is going to be GCC 4.2... So yeah that's a caveat. My testing requires installing llvm (which includes clang).

This may change in OpenBSD 6.1 (https://www.phoronix.com/scan.php?page=news_item&px=OpenBSD-Adds-LLVM-To-Base)

On OpenBSD I am using CC=/usr/local/bin/clang CXX=/usr/local/bin/clang++ with python off. I was only really intending preliminary OpenBSD support in this patch. I may have promised too much 😄

@tony

tony commented Oct 25, 2016

Copy link
Copy Markdown
Contributor Author

A few things,

  1. current master @ 72cf9b5 is broken with FreeBSD. So this PR remedies that.
  2. I'm currently in the process of going through OpenBSD setup and see what's needed. Default compiler isn't going to support C++11. It's common to install gcc5 and llvm (includes clang) after install due to these limitations.
  3. I am going to write docs for installation on OpenBSD and FreeBSD and QA all systems once again.

Comment thread CMakeLists.txt
# Always use libc++ on Clang
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "BSD")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")

@tony tony Oct 25, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On OpenBSD 6.0 (clang 3.8) and FreeBSD 11-STABLE (system clang), this will raise a warning clang-3.8: warning: argument unused during compilation: '-stdlib=libc++'

Comment thread CMakeLists.txt
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even when removing these, OpenBSD 6.0 will do this on linking:

Scanning dependencies of target nanogui
[ 88%] Linking CXX shared library libnanogui.so
/usr/bin/ld: cannot find -lc++
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error 1 in . (CMakeFiles/nanogui.dir/build.make:157 'libnanogui.so')
*** Error 1 in . (CMakeFiles/Makefile2:107 'CMakeFiles/nanogui.dir/all')
*** Error 1 in /root/study/c++/nanogui/build (Makefile:128 'all')

@tony

tony commented Oct 26, 2016

Copy link
Copy Markdown
Contributor Author
  • Added docs
  • Tested again on FreeBSD 11-STABLE, OpenBSD (GCC 4.7 and Clang 3.8) and MacOS Sierra
  • Did some more research, the -stdlib=libc++ flag won't work on the BSD's. It will fail compilation phase. I think for the BSD's letting clang find the standard lib is best choice.

@wjakob

wjakob commented Oct 28, 2016

Copy link
Copy Markdown
Owner

Merged, thank you!

@wjakob
wjakob merged commit 244db2d into wjakob:master Oct 28, 2016
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