Last active
April 30, 2019 06:10
-
-
Save RCL/6e2491729977dc9ba55967edc988b0bc to your computer and use it in GitHub Desktop.
Options to compile against UE4's libc++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compile: | |
-nostdinc++ -I $UE_THIRD_PARTY_DIR/Linux/LibCxx/include/ -I $UE_THIRD_PARTY_DIR/Linux/LibCxx/include/c++/v1 | |
Link: | |
-nodefaultlibs -L $UE_THIRD_PARTY_DIR/Linux/LibCxx/lib/Linux/x86_64-unknown-linux-gnu/ $UE_THIRD_PARTY_DIR/Linux/LibCxx/lib/Linux/x86_64-unknown-linux-gnu/libc++.a $UE_THIRD_PARTY_DIR/Linux/LibCxx/lib/Linux/x86_64-unknown-linux-gnu/libc++abi.a -lm -lc -lgcc_s -lgcc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recently dug into this, and found that
-nodefaultlibs
together with-lc -lm -lgcc_s -lgcc
linker flags are not necessary and should not present, while-stdlib=libc++
is necessary.So, the full flags should look something like:
CXX_FLAGS="-stdlib=libc++ -std=c++11 -nostdinc++ -I $UE_THIRD_PARTY_DIR/Linux/LibCxx/include/ -I $UE_THIRD_PARTY_DIR/Linux/LibCxx/include/c++/v1"
LD_FLAGS="-L$UE_THIRD_PARTY_DIR/Linux/LibCxx/lib/Linux/x86_64-unknown-linux-gnu/ -lc++ -lc++abi"
Furthermore, when using CMAKE, especially when building
grpc
withgoogle/benchmark
, the C++ feature testing usesclang++
alone to perform both compiling and linking (of course, internally,clang++
invokesld
for linking), so one has to pass the linker flags throughclang++
- otherwise, the feature testing code snippets, such asstd_regex.cpp
, won't link correctly, and thus preventing subsequent building, so correct flags for buildinggrpc
against UE4's staticlibc++/abi.a
should look like:CLANG_FLAGS_WITH_CMAKE_FEATURE_TESTING="${CXX_FLAGS} ${LD_FLAGS}"
Finally,
ldd
is a useful tool to check shared library dependencies of an executable - runldd <binary>
, and it should not contain a dependency tolibc++.so.1
, because the flags above should link your binary statically against UE4's staticlibc++/abi.a
libs - otherwise, if there does contain a dependency tolibc++.so.1
, then something must not be working correctly!