文章目录
  1. 1. 问题来源
  2. 2. 解决方案
  3. 3. TIP

问题来源

尝试在UE5中使用本地编译的aws-sdk-cpp,并需要在UE的windows编辑器里,交叉编译linux版本。

编译aws-sdk-cpp的方法参照了Build the AWS SDK for C++ on Linux/macOS,在UE项目中引入库的方法,参照了How to Integrate the AWS C++ SDK with Unreal Engine

在Windows编辑器中编译正常,打包Windows也正常,但交叉编译linux版本时出现链接错误,提示undefined symbol: Aws::Utils::DateTime::DateTime,如下

1
2
[2023.09.14-01.59.44:568][655]UATHelper: Packaging (Linux): ld.lld: error: undefined symbol: Aws::Utils::DateTime::DateTime(std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > > const&)
[2023.09.14-01.59.44:568][655]UATHelper: Packaging (Linux): >>> referenced by AWSCredentials.h:36 (D:/Projects/DT/MapEditorUE/ThirdParty/AWS/Include\aws/core/auth\AWSCredentials.h:36)

解决方案

尝试了各种动态库,静态库,均报同样错误。

最终发现,编译aws-sdk-cpp时,需要使用clang,而非gcc,因为Unreal的交叉编译使用的就是clang(似乎还是定制过的),一些c++标准的函数符号似乎存在差异,导致了这个问题。

使用clang编译可在cmake前用环境变量指定,并需要设定-DCMAKE_CXX_FLAGS="-stdlib=libc++",否则找不到libc++库

1
2
3
4
5
6
7
8
9
# 指定使用clang作为编译器
export CXX=/path/to/clang++
export CC=/path/to/clang

# cmake时指定-DCMAKE_CXX_FLAGS="-stdlib=libc++"
cmake ../../aws-sdk-cpp -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/local/ -DCMAKE_INSTALL_PREFIX=/usr/local/ -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_FLAGS="-stdlib=libc++"

# make
make -j 8

TIP

如果不设定-DCMAKE_CXX_FLAGS="-stdlib=libc++"cmake可能会报如下错误,因为clang默认不会取找gcc的库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
CMake Error at /usr/local/share/cmake-3.22/Modules/CMakeTestCXXCompiler.cmake:62 (message):
The C++ compiler

"/usr/bin/clang++"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /home/SENSETIME/sunxia/Develop/Programs/aws-sdk-cpp-build/test/CMakeFiles/CMakeTmp

Run Build Command(s):/bin/make -f Makefile cmTC_fba77/fast && /bin/make -f CMakeFiles/cmTC_fba77.dir/build.make CMakeFiles/cmTC_fba77.dir/build
make[1]: Entering directory '/home/SENSETIME/sunxia/Develop/Programs/aws-sdk-cpp-build/test/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_fba77.dir/testCXXCompiler.cxx.o
/usr/bin/clang++ -MD -MT CMakeFiles/cmTC_fba77.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_fba77.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_fba77.dir/testCXXCompiler.cxx.o -c /home/SENSETIME/sunxia/Develop/Programs/aws-sdk-cpp-build/test/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking CXX executable cmTC_fba77
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_fba77.dir/link.txt --verbose=1
/usr/bin/clang++ -rdynamic CMakeFiles/cmTC_fba77.dir/testCXXCompiler.cxx.o -o cmTC_fba77
/usr/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [CMakeFiles/cmTC_fba77.dir/build.make:100: cmTC_fba77] Error 1
make[1]: Leaving directory '/home/SENSETIME/sunxia/Develop/Programs/aws-sdk-cpp-build/test/CMakeFiles/CMakeTmp'
make: *** [Makefile:127: cmTC_fba77/fast] Error 2





CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:152 (project)
文章目录
  1. 1. 问题来源
  2. 2. 解决方案
  3. 3. TIP