我在编译OpenGL Superbible, 6th ed随附的示例代码时遇到问题。我正在使用Ubuntu 19.04和CMake 3.13.4。我有所有必要的依赖关系。 CMake执行没有问题(“ cmake”。),但是当我输入make命令时,它会失败。
我对它与GLFW有关,但我不知道如何更改CMake才能起作用。
这里是示例代码的链接。 https://github.com/openglsuperbible/sb6code
我已经解决了CMakeLists.txt文件第13行的问题,但仍未编译。
发件人:
if(WIN32)
set(COMMON_LIBS sb6 optimized GLFW_r32 debug GLFW_d32)
elif (UNIX)
set(COMMON_LIBS sb6 glfw ${GLFW_LIBRARIES} GL rt dl)
else()
set(COMMON_LIBS sb6)
收件人:
if(WIN32)
set(COMMON_LIBS sb6 optimized GLFW_r32 debug GLFW_d32)
else()
set(COMMON_LIBS sb6 glfw ${GLFW_LIBRARIES} GL rt dl)
我尝试将find_package(glfw3 3.2必需)添加到文件的开头,但仍然没有成功。
这里是我当前的CMakeLists.txt:
cmake_minimum_required (VERSION 2.6)
project (SuperBible6)
LINK_DIRECTORIES( ${CMAKE_SOURCE_DIR}/lib )
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(WIN32)
set(COMMON_LIBS sb6 optimized GLFW_r32 debug GLFW_d32)
else()
set(COMMON_LIBS sb6 glfw ${GLFW_LIBRARIES} GL rt dl)
endif()
IF(APPLE)
INCLUDE_DIRECTORIES(/System/Library/Frameworks)
FIND_LIBRARY(COCOA_LIBRARY Cocoa)
FIND_LIBRARY(OpenGL_LIBRARY OpenGL)
FIND_LIBRARY(IOKit_LIBRARY IOKit)
MARK_AS_ADVANCED(COCOA_LIBRARY OpenGL_LIBRARY)
SET(EXTRA_LIBS ${COCOA_LIBRARY} ${IOKit_LIBRARY} ${OpenGL_LIBRARY})
SET(EXTRA_LIBS ${EXTRA_LIBS} /usr/local/lib/libglfw.a)
ENDIF(APPLE)
set(COMMON_LIBS ${COMMON_LIBS} ${EXTRA_LIBS})
add_library(sb6
src/sb6/sb6.cpp
src/sb6/sb6ktx.cpp
src/sb6/sb6object.cpp
src/sb6/sb6shader.cpp
src/sb6/gl3w.c
)
set(RUN_DIR ${PROJECT_SOURCE_DIR}/bin)
set(EXAMPLES
alienrain
basicfbo
blendmatrix
blinnphong
bumpmapping
clipdistance
csflocking
cubemapenv
cubicbezier
deferredshading
depthclamp
dispmap
dof
envmapsphere
equirectangular
fragcolorfrompos
fragmentlist
grass
gsculling
gslayered
gsquads
gstessellate
hdrbloom
hdrexposure
hdrtonemap
indexedcube
instancedattribs
julia
ktxview
linesmooth
movingtri
msaanative
multidrawindirect
multimaterial
multiscissor
multiviewport
noise
noperspective
normalviewer
objectexploder
perf-readpixels
perpixelgloss
phonglighting
polygonsmooth
prefixsum
prefixsum2d
programinfo
raytracer
rimlight
sampleshading
# sb6mrender
shadowmapping
shapedpoints
simpleclear
simpletexcoords
simpletexture
singlepoint
singletri
sparsetexture
spinnycube
springmass
ssao
starfield
stereo
subroutines
tessellatedcube
tessellatedgstri
tessellatedtri
tessmodes
tesssubdivmodes
toonshading
tunnel
wrapmodes
)
if (WIN32)
set(EXAMPLES ${EXAMPLES} win32raw)
endif()
#if(UNIX)
# add_executable(xraw src/xraw/xraw.c)
# target_link_libraries(xraw GL X11 m)
#endif(UNIX)
foreach(EXAMPLE ${EXAMPLES})
add_executable(${EXAMPLE} WIN32 src/${EXAMPLE}/${EXAMPLE}.cpp)
target_link_libraries(${EXAMPLE} ${COMMON_LIBS})
if(MSVC)
configure_file(${PROJECT_SOURCE_DIR}/build/vs2010/VisualStudioUserFile.vcproj.user.in ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.vcproj.user @ONLY)
configure_file(${PROJECT_SOURCE_DIR}/build/vs2010/VisualStudioUserFile.vcxproj.user.in ${CMAKE_CURRENT_BINARY_DIR}/${EXAMPLE}.vcxproj.user @ONLY)
endif(MSVC)
endforeach(EXAMPLE)
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LINUX")
ENDIF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
include_directories( include )
include_directories( extern/glfw-2.7.6/include )
ADD_CUSTOM_TARGET(debug ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Debug ${PROJECT_SOURCE_DIR})
ADD_CUSTOM_TARGET(release ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=Release ${PROJECT_SOURCE_DIR})
这是我得到的错误:
myron@myron-UX430UA:~/Desktop/sb6/sb6code-master$ make V=1
Scanning dependencies of target sb6
[ 1%] Building CXX object CMakeFiles/sb6.dir/src/sb6/sb6.cpp.o
[ 2%] Building CXX object CMakeFiles/sb6.dir/src/sb6/sb6ktx.cpp.o
[ 2%] Building CXX object CMakeFiles/sb6.dir/src/sb6/sb6object.cpp.o
[ 3%] Building CXX object CMakeFiles/sb6.dir/src/sb6/sb6shader.cpp.o
[ 4%] Building C object CMakeFiles/sb6.dir/src/sb6/gl3w.c.o
[ 4%] Linking CXX static library lib/libsb6.a
[ 4%] Built target sb6
Scanning dependencies of target wrapmodes
[ 5%] Building CXX object CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o
[ 6%] Linking CXX executable bin/wrapmodes
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o: in function `sb6::application::run(sb6::application*)':
wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x8b): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xa1): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xb0): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xbf): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xd5): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o:wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xf5): more undefined references to `glfwOpenWindowHint' follow
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o: in function `sb6::application::run(sb6::application*)':
wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x133): undefined reference to `glfwGetDesktopMode'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x18b): undefined reference to `glfwOpenWindow'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x1e9): undefined reference to `glfwOpenWindow'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x25b): undefined reference to `glfwSetMousePosCallback'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x267): undefined reference to `glfwSetMouseWheelCallback'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x280): undefined reference to `glfwEnable'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x289): undefined reference to `glfwDisable'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x29a): undefined reference to `glfwGetWindowParam'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x3bc): undefined reference to `glfwGetWindowParam'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/wrapmodes.dir/build.make:85: bin/wrapmodes] Error 1
make[1]: *** [CMakeFiles/Makefile2:137: CMakeFiles/wrapmodes.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
编辑:尽管看不到任何其他信息,但运行“ make V = 1”。
答案 0 :(得分:0)
我已更改代码和cmake文件以与GLFW3一起使用。现在,该项目将编译并运行。我将其上载到github:https://github.com/mlioz/sb6code_fixed