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

Link with C++ compiler instead of linking with C compiler and adding -lstdc++ #257

Open
ryandesign opened this issue Dec 29, 2021 · 1 comment
Labels

Comments

@ryandesign
Copy link

The build system uses the C compiler as the linker and adds the flag -lstdc++, for example:

/usr/bin/clang objects/gui.o  -lstdc++ -L/opt/local/lib -lsmooth-0.9  -L/opt/local/lib -Wl,-headerpad_max_install_names -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -arch x86_64 -o bin/freac

This is wrong because the C++ standard library being used might not be libstdc++; the default C++ standard library on macOS has been libc++ since OS X 10.9. Because this mistake is so common the linker seems to silently transform -lstdc++ to -lc++ to correct the problem, but it would be better not to make the mistake in the first place.

Usually, when you're linking stuff that came from C++ code, I've seen projects use the C++ compiler (not the C compiler) as the linker; that way, you don't have to specify to link with a C++ standard library. Make sure to use the CXXFLAGS environment variable when you do so in case the user has specified a -stdlib flag there that differs from what the default C++ standard library is.

@ryandesign ryandesign added the bug label Dec 29, 2021
@enzo1982
Copy link
Owner

This is fixed now with commit 3e9100c.

CXXFLAGS is not used for linking, though, as that would add compile-time flags to the linker command line. To use an alternative stdlib, the -stdlib option should be added to both, CXXFLAGS and LDFLAGS.

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

No branches or pull requests

2 participants