Skip to content

Instantly share code, notes, and snippets.

@RCL
Last active April 30, 2019 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RCL/6e2491729977dc9ba55967edc988b0bc to your computer and use it in GitHub Desktop.
Save RCL/6e2491729977dc9ba55967edc988b0bc to your computer and use it in GitHub Desktop.
Options to compile against UE4's libc++
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
@llint
Copy link

llint commented Apr 30, 2019

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 with google/benchmark, the C++ feature testing uses clang++ alone to perform both compiling and linking (of course, internally, clang++ invokes ld for linking), so one has to pass the linker flags through clang++ - otherwise, the feature testing code snippets, such as std_regex.cpp, won't link correctly, and thus preventing subsequent building, so correct flags for building grpc against UE4's static libc++/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 - run ldd <binary>, and it should not contain a dependency to libc++.so.1, because the flags above should link your binary statically against UE4's static libc++/abi.a libs - otherwise, if there does contain a dependency to libc++.so.1, then something must not be working correctly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment