Undefined symbols for architecture x86_64: “_glBeg

2019-09-17 22:23发布

问题:

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> ...)