C++学习(四零四)hidden symbol `atexit‘ in XXX is referenced by DSO

Posted hankern

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++学习(四零四)hidden symbol `atexit‘ in XXX is referenced by DSO相关的知识,希望对你有一定的参考价值。

执行如下语句时报错:

/bin/sh e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/libtool --mode=link --silent D:/android-ndk-r19c/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android28-clang++  gdalinfo_bin.lo  e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/libgdal.la  -o gdalinfo
D:\\android-ndk-r19c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\\ld: .libs/gdalinfo: hidden symbol `atexit' in D:\\android-ndk-r19c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin/../sysroot/usr/lib/aarch64-linux-android/28\\crtbegin_dynamic.o is referenced by DSO
D:\\android-ndk-r19c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\\ld: final link failed: Bad value
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

编译语句如下:

/bin/sh e:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/libtool --mode=compile --silent --tag=CXX D:/android-ndk-r19c/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android28-clang++ -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/port -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/gcore -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/alg -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/ogr -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/ogr/ogrsf_frmts -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/gnm -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/apps -g -O2  -Wall -Wextra -Winit-self -Wunused-parameter -Wformat -Werror=format-security -Wno-format-nonliteral -Wshorten-64-to-32 -Wshadow -Werror=vla -Wdate-time -Wnull-dereference -Wextra-semi -Wcomma -Wfloat-conversion -Wdocumentation -Wno-documentation-deprecated-sync -Wunused-private-field -Wmissing-prototypes -Wmissing-declarations -Wnon-virtual-dtor -Woverloaded-virtual -fno-operator-names -Wzero-as-null-pointer-constant -Wimplicit-fallthrough  -fno-use-cxa-atexit -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/frmts/vrt -DGNM_ENABLED -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/port  -DGDAL_COMPILATION -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/ogr/ogrsf_frmts/geojson/libjson -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/ogr/ogrsf_frmts/geojson -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/ogr/ogrsf_frmts/generic -Ie:/osg-osgearth-source/other_3rdParty/gdal-2.3.2/gnm -c -o gdalinfo_bin.lo gdalinfo_bin.cpp

去掉编译选项 -fno-use-cxa-atexit 依然报错。

C++学习(三九四)relocation R_AARCH64_ADR_PREL_PG_HI21 undefined reference to `__dso_handle‘_hankern的专栏-CSDN博客报错原因一样,因为代码里存在mutex,但是采用-fno-use-cxa-atexit 这个已经不起作用。同时使用-fno-use-cxa-atexit  -coverage也不起作用。单独使用-coverage时,gdal库编译通不过。

有地方提到增加编译选项-coverage,但是会报以下错:

.libs/gdalinfo_bin.o: In function `__llvm_gcov_writeout':
gdalinfo_bin.cpp:(.text+0x7f8): undefined reference to `llvm_gcda_start_file'
gdalinfo_bin.cpp:(.text+0x81c): undefined reference to `llvm_gcda_emit_function'
gdalinfo_bin.cpp:(.text+0x82c): undefined reference to `llvm_gcda_emit_arcs'
gdalinfo_bin.cpp:(.text+0x850): undefined reference to `llvm_gcda_emit_function'
gdalinfo_bin.cpp:(.text+0x860): undefined reference to `llvm_gcda_emit_arcs'
gdalinfo_bin.cpp:(.text+0x884): undefined reference to `llvm_gcda_emit_function'
gdalinfo_bin.cpp:(.text+0x894): undefined reference to `llvm_gcda_emit_arcs'
gdalinfo_bin.cpp:(.text+0x8b8): undefined reference to `llvm_gcda_emit_function'
gdalinfo_bin.cpp:(.text+0x8c8): undefined reference to `llvm_gcda_emit_arcs'
gdalinfo_bin.cpp:(.text+0x8cc): undefined reference to `llvm_gcda_summary_info'
gdalinfo_bin.cpp:(.text+0x8d4): undefined reference to `llvm_gcda_end_file'
.libs/gdalinfo_bin.o: In function `__llvm_gcov_init':
gdalinfo_bin.cpp:(.text+0x93c): undefined reference to `llvm_gcov_init'
D:\\android-ndk-r19c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\\ld: .libs/gdalinfo: hidden symbol `atexit' in D:\\android-ndk-r19c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin/../sysroot/usr/lib/aarch64-linux-android/28\\crtbegin_dynamic.o is referenced by DSO
D:\\android-ndk-r19c\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\\ld: final link failed: Bad value
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

以上是关于C++学习(四零四)hidden symbol `atexit‘ in XXX is referenced by DSO的主要内容,如果未能解决你的问题,请参考以下文章

C++学习(四零三)-lm -ldl

C++学习(四零八)CMake操作系统类型android windows ios

C++学习(四零六)AI三大法则

C++学习(四零九)CMAKE_SYSTEM_NAME确定操作系统类型

C++学习(四四零)android studio如何关联cmake

C++学习(四零七)ALL_BUILDINSTALLZERO_CHECK