Undefined symbols for architecture x86_64: “_glBegin”

只谈情不闲聊 提交于 2019-12-12 04:24:36

问题


I'm trying to build a source code and after passing/fixing a ton of errors, I'm stuck at a point where I have no idea how to fix. I'm novice in building sources but I tried to search for this error and none of them worked me although I'm not sure if I implemented them correctly. I'm on OSX 10.8.5 with XCode 5.1.1

I'm striving to make a cmake file but at 75% I'm getting this error (brief form):

Undefined symbols for architecture x86_64: "_glBegin", referenced from: AlembicHolderOverride::draw(MHWRender::MDrawContext const&, MUserData const*) in alembicHolderOverride.cpp.o

And this is portion of the cmakelist that I have:

# Fix to stop crash on OSX < 10.9
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.8)

# Compiler flags
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
    # Disable some of the bullshit warnings MSVC wants to barf
    add_definitions( "-W3 -MP -D_CRT_SECURE_NO_WARNINGS -wd4005 -wd4996 -wd4305 -wd4244 -nologo" )
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()

IF( "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin" )
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03 -stdlib=libstdc++ -framework OpenGL")

endif()

IF( "${CMAKE_SYSTEM_NAME}" MATCHES "Linux" )
    add_definitions(-D_LINUX)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fvisibility=hidden -fPIC")
endif()

I really appreciate any help on this in advance, and please don't hesitate to let me know if any part of that Cmakelist build flags is wrong since I'm not really experienced in this.


回答1:


You need to link to OpenGL:

find_package(OpenGL REQUIRED)
...
add_(library|executable)(<your-target> ...)
...
target_include_directories(<your-target> PRIVATE ${OPENGL_INCLUDE_DIR})
target_link_libraries(<your-target> PRIVATE ${OPENGL_LIBRARIES})

(you may need PUBLIC linking if it's a library with public headers using OpenGL)

Or the traditional way:

find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
link_libraries(${OPENGL_LIBRARIES})
...
add_(library|executable)(<your-target> ...)


来源:https://stackoverflow.com/questions/31463895/undefined-symbols-for-architecture-x86-64-glbegin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!