gpt4 book ai didi

c++ - 'make' 的输出是共享对象而不是可执行文件

转载 作者:搜寻专家 更新时间:2023-10-31 02:13:29 26 4
gpt4 key购买 nike

编辑:这似乎是一个 g++ 问题,因为使用 clang++ 编译会输出一个可执行文件。

我编写了一个具有主要功能的 C++ 应用程序、创建应用程序窗口、加载 3D fbx 文件并使用 opengl 绘制该文件。要创建用于编译的 Makefile,我使用的是 CMakeLists.txt 文件:

cmake_minimum_required(VERSION 2.8)
project(solight)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
INCLUDE_DIRECTORIES(lib/include)

###########################################
#SET THIS TO X32 IN CASE OF A 32 BIT SYSTEM
###########################################
set (ARCH x64)

set (SRC_LIST
src/assetmanager.cpp src/assetmanager.h
src/mesh.cpp src/mesh.h
src/model.cpp src/model.h
src/modelloader.h
src/main.cpp
src/math.h
src/fbxmodelloader.cpp src/fbxmodelloader.h
src/rendermodule.h
src/openglrendermodule.cpp src/openglrendermodule.h
src/textureloader.h
src/engine.cpp src/enginemodules.cpp src/engine.h
)


##########################
#EXTERNAL LIBRARY HANDLING
##########################

set (LINUX_DEPS
libfbxsdk.a
pthread
libSDL2.a
GL
libGLEW.a
dl
)

set (WIN32_DEPS
)

set (APPLE_DEPS
)

if (UNIX AND NOT APPLE)
set (DEPS ${LINUX_DEPS})
set (OS Linux)
endif()

if (APPLE)
set (DEPS ${APPLE_DEPS})
set (OS Apple)
endif()

if (WIN32)
set (DEPS ${WIN32_DEPS})
set (OS WIN32)
endif()


LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/${OS}/${ARCH})

####################
#EXECUTBALE CREATION
####################

add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} ${DEPS})

因此在运行 cmake 创建的 makefile 后,输出不是预期的可执行文件,而是共享对象文件。如果我在其上运行文件命令,这是输出:

solight: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=f20c07c8743a70bca20d4a0d9f50fcb108b8140e, not stripped

执行时

 /lib64/ld-linux-x86-64.so.2 ./solight --verify

程序按预期执行。

但是当我通过终端执行文件时它运行得很好,创建窗口并渲染模型。

关于为什么这是一个共享对象文件的任何解释?提前致谢。

编辑:运行时

make VERBOSE=1

输出是:

    /usr/bin/cmake -H/home/wouter/Documents/Solight -B/home/wouter/Documents/Solight/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/wouter/Documents/Solight/build/CMakeFiles /home/wouter/Documents/Solight/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/wouter/Documents/Solight/build'
make -f CMakeFiles/solight.dir/build.make CMakeFiles/solight.dir/depend
make[2]: Entering directory '/home/wouter/Documents/Solight/build'
cd /home/wouter/Documents/Solight/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/wouter/Documents/Solight /home/wouter/Documents/Solight /home/wouter/Documents/Solight/build /home/wouter/Documents/Solight/build /home/wouter/Documents/Solight/build/CMakeFiles/solight.dir/DependInfo.cmake --color=
Dependee "/home/wouter/Documents/Solight/build/CMakeFiles/solight.dir/DependInfo.cmake" is newer than depender "/home/wouter/Documents/Solight/build/CMakeFiles/solight.dir/depend.internal".
Dependee "/home/wouter/Documents/Solight/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/wouter/Documents/Solight/build/CMakeFiles/solight.dir/depend.internal".
Scanning dependencies of target solight
make[2]: Leaving directory '/home/wouter/Documents/Solight/build'
make -f CMakeFiles/solight.dir/build.make CMakeFiles/solight.dir/build
make[2]: Entering directory '/home/wouter/Documents/Solight/build'
[ 11%] Building CXX object CMakeFiles/solight.dir/src/assetmanager.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/assetmanager.cpp.o -c /home/wouter/Documents/Solight/src/assetmanager.cpp
[ 22%] Building CXX object CMakeFiles/solight.dir/src/mesh.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/mesh.cpp.o -c /home/wouter/Documents/Solight/src/mesh.cpp
[ 33%] Building CXX object CMakeFiles/solight.dir/src/model.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/model.cpp.o -c /home/wouter/Documents/Solight/src/model.cpp
[ 44%] Building CXX object CMakeFiles/solight.dir/src/main.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/main.cpp.o -c /home/wouter/Documents/Solight/src/main.cpp
[ 55%] Building CXX object CMakeFiles/solight.dir/src/fbxmodelloader.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/fbxmodelloader.cpp.o -c /home/wouter/Documents/Solight/src/fbxmodelloader.cpp
[ 66%] Building CXX object CMakeFiles/solight.dir/src/openglrendermodule.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/openglrendermodule.cpp.o -c /home/wouter/Documents/Solight/src/openglrendermodule.cpp
[ 77%] Building CXX object CMakeFiles/solight.dir/src/engine.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/engine.cpp.o -c /home/wouter/Documents/Solight/src/engine.cpp
[ 88%] Building CXX object CMakeFiles/solight.dir/src/enginemodules.cpp.o
/usr/bin/c++ -I/home/wouter/Documents/Solight/lib/include -std=c++14 -o CMakeFiles/solight.dir/src/enginemodules.cpp.o -c /home/wouter/Documents/Solight/src/enginemodules.cpp
[100%] Linking CXX executable solight
/usr/bin/cmake -E cmake_link_script CMakeFiles/solight.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++14 CMakeFiles/solight.dir/src/assetmanager.cpp.o CMakeFiles/solight.dir/src/mesh.cpp.o CMakeFiles/solight.dir/src/model.cpp.o CMakeFiles/solight.dir/src/main.cpp.o CMakeFiles/solight.dir/src/fbxmodelloader.cpp.o CMakeFiles/solight.dir/src/openglrendermodule.cpp.o CMakeFiles/solight.dir/src/engine.cpp.o CMakeFiles/solight.dir/src/enginemodules.cpp.o -o solight -L/home/wouter/Documents/Solight/lib/Linux/x64 -rdynamic -Wl,-Bstatic -lfbxsdk -Wl,-Bdynamic -lpthread -Wl,-Bstatic -lSDL2 -Wl,-Bdynamic -lGL -Wl,-Bstatic -lGLEW -Wl,-Bdynamic -ldl -Wl,-rpath,/home/wouter/Documents/Solight/lib/Linux/x64
/home/wouter/Documents/Solight/lib/Linux/x64/libfbxsdk.a(fbxutils.o): In function `fbxsdk_2015_1::FbxPathUtils::GenerateFileName(char const*, char const*)':
(.text+0x4c8): warning: the use of `tempnam' is dangerous, better use `mkstemp'
make[2]: Leaving directory '/home/wouter/Documents/Solight/build'
[100%] Built target solight
make[1]: Leaving directory '/home/wouter/Documents/Solight/build'
/usr/bin/cmake -E cmake_progress_start /home/wouter/Documents/Solight/build/CMakeFiles 0

最佳答案

当使用特殊的 CFLAGS 编译应用程序时可能会发生这种情况,例如-pie -fPIE:

$ echo 'int main() { return 0; }' | gcc -x c - -fPIE -pie
$ file a.out
a.out: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24,

也许您可以使用 VERBOSE=1 运行您的 make 并查看是否是这种情况?一般来说,file 可能会使用启发式方法来识别文件类型,因此您不应过分依赖它。

至于 ld.so 的错误,您使用了错误的 32 位动态链接器来运行 64 位应用程序。请改用/lib64/ld-linux-x86-64.so.2(如 file 告诉您的那样)。

编辑:另一种选择是您的 GCC 是使用 --enable-default-pie 构建的这似乎是 modern Ubuntu 的情况.您可以通过使用 CFLAGS=-no-pie(或 -nopie,取决于 GCC 版本)来禁用此功能,但我宁愿不这样做 - PIE 的可执行文件允许 ASLR 做得更好,从而使您的系统更安全。

关于c++ - 'make' 的输出是共享对象而不是可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41303584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com