This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Linux c++ error: undefined reference to 'dlopen'
(12 answers)
Closed 4 years ago.
I need some basic understanding,
I have 4 files in this folder
Makefile , libfoo_8_3.so , libfoo_9_3.so , test.c
I compile test.c to make object file test.o and .d file. This Compiles fine
Those two dynamic libraries (libfoo_8_3.so libfoo_9_3.so)are used by my c program
I wanted to make executable.
I am using Makefile, because I needed headers and structures from c files present in the different folder.
I want to make an executable binary,
when I do something like
gcc -fno-builtin-log -fno-omit-frame-pointer -msse2 -DMEMS_DEBUG -DMEMS_DISABLED -D__HMAP_64BIT_COMPLIANT_ID_LENGTH__ -DNETOID_LINUX -D_REENTRANT -DXML_BYTE_ORDER=12 -DNX_BYTE_ORDER=12 -DTHIRTY_TWO_BIT -DALLOW_ISERVER_H323 -D_POSIX_PTHREAD_SEMANTICS -DMEMS_DEBUG -ggdb -L/usr/local/lib -L/usr/lib64 -L/SBC/lib/x86_64 -L/SBC/pkgs_x86_64/def/lib -L/SBC/bin/x86_64 -I(Include many folders)
-o test test.o
This gives me following error ->
est.o: In function `main':
/SBC/ser/test.c:33: undefined reference to `dlopen'
/SBC/ser/test.c:35: undefined reference to `dlopen'
/SBC/ser/test.c:50: undefined reference to `dlsym'
/SBC/ser/test.c:52: undefined reference to `dlsym'
/SBC/ser/test.c:68: undefined reference to `tracer_tag_key'
/SBC/ser/test.c:68: undefined reference to `pthread_getspecific'
/SBC/ser/test.c:68: undefined reference to `netLogStruct'
/SBC/ser/test.c:68: undefined reference to `NetLogModuleFacilities'
/SBC/ser/test.c:68: undefined reference to `NetLogModuleNames'
/SBC/ser/test.c:68: undefined reference to `NetSyslogSprintf'
/SBC/ser/test.c:68: undefined reference to `netLogStruct'
/SBC/ser/test.c:68: undefined reference to `NetLogModuleNames'
/SBC/ser/test.c:74: undefined reference to `tracer_tag_key'
/SBC/ser/test.c:74: undefined reference to `pthread_getspecific'
/SBC/ser/test.c:74: undefined reference to `netLogStruct'
/SBC/ser/test.c:74: undefined reference to `NetLogModuleFacilities'
/SBC/ser/test.c:74: undefined reference to `NetLogModuleNames'
/SBC/ser/test.c:74: undefined reference to `NetSyslogSprintf'
/SBC/ser/test.c:74: undefined reference to `netLogStruct'
/SBC/ser/test.c:74: undefined reference to `NetLogModuleNames'
/SBC/ser/test.c:82: undefined reference to `tracer_tag_key'
/SBC/ser/test.c:82: undefined reference to `pthread_getspecific'
/SBC/ser/test.c:82: undefined reference to `netLogStruct'
/SBC/ser/test.c:82: undefined reference to `NetLogModuleFacilities'
/SBC/ser/test.c:82: undefined reference to `NetLogModuleNames'
/SBC/ser/test.c:82: undefined reference to `NetSyslogSprintf'
/SBC/ser/test.c:82: undefined reference to `netLogStruct'
/SBC/ser/test.c:82: undefined reference to `NetLogModuleNames'
I need a proper understanding of this , or how can I resolve this ?
Related
so i was trying to set up vulkan on vscode in windows.
and i strugle to fix the link errors.
at first i had problems with GLFM
but it looks like i sorted it out, by compiling it with mingw myself.
but now i guess the following link error
undefined reference to `vkEnumerateInstanceExtensionProperties#12'
how should i resolve that issue?
my makefile looks like that at the moment:
DIR1 := external/GLFM/include
DIR2 := external/glm/
DIR3 := external/vulkan/Include
INC=$(DIR1) $(DIR2) $(DIR3)
INC_PARAMS=$(foreach d, $(INC), -I$d)
LDPATHS2 := -Lexternal/GLFM/Lib/ -Lexternal/vulkan/Lib/
LDLIBS = -lglfw3 -lvulkan-1 -lgdi32
VulkanTest: main.cpp
g++ $(CFLAGS) $(INC_PARAMS) $(LDPATHS2) -o VulkanTest main.cpp $(LDLIBS)
EDIT:
i have added the -lgdi32 as that seemed to get rid of all of those
link errors:
C:\Users\Michael\AppData\Local\Temp\ccRgsVDp.o:main.cpp:(.text.startup+0x7c): undefined reference to `vkEnumerateInstanceExtensionProperties#12'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x12b): undefined reference to `_imp__CreateDCW#16'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x166): undefined reference to `_imp__GetDeviceCaps#8'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x181): undefined reference to `_imp__GetDeviceCaps#8'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x1d4): undefined reference to `_imp__GetDeviceCaps#8'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x257): undefined reference to `_imp__GetDeviceCaps#8'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x29f): undefined reference to `_imp__DeleteDC#4'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xa49): undefined reference to `_imp__GetDeviceCaps#8'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xa64): undefined reference to `_imp__GetDeviceCaps#8'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xf06): undefined reference to `_imp__CreateDCW#16'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xf23): undefined reference to `_imp__GetDeviceGammaRamp#8'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xf33): undefined reference to `_imp__DeleteDC#4'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x107b): undefined reference to `_imp__CreateDCW#16'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x1098): undefined reference to `_imp__SetDeviceGammaRamp#8'
external/GLFM/Lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x10a8): undefined reference to `_imp__DeleteDC#4'
external/GLFM/Lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x1f5): undefined reference to `_imp__CreateDIBSection#24'
external/GLFM/Lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x268): undefined reference to `_imp__CreateBitmap#20'
external/GLFM/Lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x295): undefined reference to `_imp__DeleteObject#4'
external/GLFM/Lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x387): undefined reference to `_imp__DeleteObject#4'
external/GLFM/Lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x397): undefined reference to `_imp__DeleteObject#4'
external/GLFM/Lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xbe1): undefined reference to `_imp__CreateRectRgn#16'
external/GLFM/Lib/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xc41): undefined reference to `_imp__DeleteObject#4'
external/GLFM/Lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x6c4): undefined reference to `_imp__DescribePixelFormat#16'
external/GLFM/Lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xbbf): undefined reference to `_imp__DescribePixelFormat#16'
external/GLFM/Lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xf4a): undefined reference to `_imp__SwapBuffers#4'
external/GLFM/Lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x126e): undefined reference to `_imp__ChoosePixelFormat#8'
external/GLFM/Lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x128b): undefined reference to `_imp__SetPixelFormat#12'
external/GLFM/Lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x15b4): undefined reference to `_imp__DescribePixelFormat#16'
external/GLFM/Lib/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x15fd): undefined reference to `_imp__SetPixelFormat#12'
I just installed GLFW3 on Ubuntu and I'm testing the example code from the documentation (http://www.glfw.org/documentation.html) and I got those errors.
I tried multiples thing like adding -ldl, but nothing seems to work.
Here is the error log (GCC):
g++ -o bin/Debug/Game obj/Debug/main.o -ldl -lglfw3 -lm -lGL -lGLU
//usr/local/lib/libglfw3.a(vulkan.c.o): In function `_glfwInitVulkan':
vulkan.c:(.text+0x42): undefined reference to `dlopen'
vulkan.c:(.text+0xa9): undefined reference to `dlsym'
//usr/local/lib/libglfw3.a(vulkan.c.o): In function `_glfwTerminateVulkan':
vulkan.c:(.text+0x382): undefined reference to `dlclose'
//usr/local/lib/libglfw3.a(vulkan.c.o): In function `glfwGetInstanceProcAddress':
vulkan.c:(.text+0x72f): undefined reference to `dlsym'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `translateKeyCode':
x11_init.c:(.text+0x6a): undefined reference to `XkbKeycodeToKeysym'
x11_init.c:(.text+0x14a): undefined reference to `XkbKeycodeToKeysym'
x11_init.c:(.text+0x177): undefined reference to `XGetKeyboardMapping'
x11_init.c:(.text+0x191): undefined reference to `XFree'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `createKeyTables':
x11_init.c:(.text+0xc3e): undefined reference to `XkbGetMap'
x11_init.c:(.text+0xc61): undefined reference to `XkbGetNames'
x11_init.c:(.text+0x137f): undefined reference to `XkbFreeNames'
x11_init.c:(.text+0x1395): undefined reference to `XkbFreeKeyboard'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `hasUsableInputMethodStyle':
x11_init.c:(.text+0x14b2): undefined reference to `XGetIMValues'
x11_init.c:(.text+0x150c): undefined reference to `XFree'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `getSupportedAtom':
x11_init.c:(.text+0x155b): undefined reference to `XInternAtom'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `detectEWMH':
x11_init.c:(.text+0x15ea): undefined reference to `XInternAtom'
x11_init.c:(.text+0x1610): undefined reference to `XInternAtom'
x11_init.c:(.text+0x1678): undefined reference to `XFree'
x11_init.c:(.text+0x16a1): undefined reference to `XFree'
x11_init.c:(.text+0x16ad): undefined reference to `XFree'
x11_init.c:(.text+0x16be): undefined reference to `XFree'
x11_init.c:(.text+0x16ca): undefined reference to `XFree'
//usr/local/lib/libglfw3.a(x11_init.c.o):x11_init.c:(.text+0x190d): more undefined references to `XFree' follow
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x194e): undefined reference to `dlopen'
x11_init.c:(.text+0x1993): undefined reference to `dlsym'
x11_init.c:(.text+0x19c1): undefined reference to `dlsym'
x11_init.c:(.text+0x19ef): undefined reference to `dlsym'
x11_init.c:(.text+0x1a1d): undefined reference to `dlsym'
x11_init.c:(.text+0x1a8b): undefined reference to `dlopen'
x11_init.c:(.text+0x1ad0): undefined reference to `dlsym'
x11_init.c:(.text+0x1afe): undefined reference to `dlsym'
x11_init.c:(.text+0x1b56): undefined reference to `XQueryExtension'
x11_init.c:(.text+0x1bdf): undefined reference to `dlopen'
x11_init.c:(.text+0x1c24): undefined reference to `dlsym'
x11_init.c:(.text+0x1c52): undefined reference to `dlsym'
x11_init.c:(.text+0x1c80): undefined reference to `dlsym'
x11_init.c:(.text+0x1cae): undefined reference to `dlsym'
x11_init.c:(.text+0x1cdc): undefined reference to `dlsym'
//usr/local/lib/libglfw3.a(x11_init.c.o):x11_init.c:(.text+0x1d0a): more undefined references to `dlsym' follow
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x214a): undefined reference to `dlopen'
x11_init.c:(.text+0x218f): undefined reference to `dlsym'
x11_init.c:(.text+0x21bd): undefined reference to `dlsym'
x11_init.c:(.text+0x21eb): undefined reference to `dlsym'
x11_init.c:(.text+0x220d): undefined reference to `dlopen'
x11_init.c:(.text+0x2252): undefined reference to `dlsym'
x11_init.c:(.text+0x2280): undefined reference to `dlsym'
x11_init.c:(.text+0x22ae): undefined reference to `dlsym'
x11_init.c:(.text+0x23b4): undefined reference to `XkbQueryExtension'
x11_init.c:(.text+0x23f3): undefined reference to `XkbSetDetectableAutoRepeat'
x11_init.c:(.text+0x2420): undefined reference to `dlopen'
Order of libraries matter. If library A depends on library B, then A must come before B on the command line.
In your case, since the glfw3 library depends on the dl library, you must switch order so that glfw3 comes before dl on the command line.
You also must link with the X11 library.
So the full command line should look something like
g++ -o bin/Debug/Game obj/Debug/main.o -lglfw3 -ldl -lm -lGL -lGLU -lX11
I'm working on a modification of the Wolfenstein 3D engine in SDL2 (using Wolf4SDL as a base) and I've run into a problem - when using -static in the linker options, I get a large variety of undefined references to various things. Here's my build log to show what I mean:
-------------- Build: Debug in Lazarus (compiler: GNU GCC Compiler)---------------
i686-w64-mingw32-g++.exe -LC:\SDL2\lib -o Lazarus.exe .objs\alu_cache.o .objs\alu_dbg_mem.o .objs\alu_gfx.o .objs\alu_hud.o .objs\alu_in.o .objs\alu_me_core.o .objs\alu_me_gui.o .objs\alu_me_symbols.o .objs\alu_me_textinput.o .objs\alu_me_tools.o .objs\alu_me_windows.o .objs\alu_menu.o .objs\alu_pak.o .objs\alu_particles.o .objs\asmcomp.o .objs\id_us_1.o .objs\vieasm.o .objs\wl_act1.o .objs\wl_act2.o .objs\wl_agent.o .objs\wl_debug.o .objs\wl_dir3dspr.o .objs\wl_draw.o .objs\wl_floorceiling.o .objs\wl_game.o .objs\wl_inter.o .objs\wl_main.o .objs\wl_play.o .objs\wl_state.o .objs\wl_text.o -static -pg -lgmon -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -mwindows
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:58: undefined reference to `_imp__timeBeginPeriod#4'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:52: undefined reference to `_imp__timeEndPeriod#4'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:58: undefined reference to `_imp__timeBeginPeriod#4'
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `SDL_TicksInit':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:106: undefined reference to `_imp__timeGetTime#0'
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:52: undefined reference to `_imp__timeEndPeriod#4'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:52: undefined reference to `_imp__timeEndPeriod#4'
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `SDL_GetTicks_REAL':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:159: undefined reference to `_imp__timeGetTime#0'
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:58: undefined reference to `_imp__timeBeginPeriod#4'
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `SDL_TicksInit':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:106: undefined reference to `_imp__timeGetTime#0'
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:52: undefined reference to `_imp__timeEndPeriod#4'
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `SDL_GetTicks_REAL':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:159: undefined reference to `_imp__timeGetTime#0'
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:58: undefined reference to `_imp__timeBeginPeriod#4'
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `SDL_TicksInit':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:106: undefined reference to `_imp__timeGetTime#0'
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:52: undefined reference to `_imp__timeEndPeriod#4'
C:\SDL2\lib\libSDL2.a(SDL_windows.o): In function `WIN_CoInitialize':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/core/windows/SDL_windows.c:68: undefined reference to `_imp__CoInitializeEx#8'
C:\SDL2\lib\libSDL2.a(SDL_windows.o): In function `WIN_CoUninitialize':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/core/windows/SDL_windows.c:87: undefined reference to `_imp__CoUninitialize#0'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_SetupAPI':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:596: undefined reference to `ImmGetIMEFileNameA#12'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:609: undefined reference to `ImmGetContext#4'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:612: undefined reference to `ImmReleaseContext#8'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetId':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:530: undefined reference to `ImmGetIMEFileNameA#12'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:545: undefined reference to `GetFileVersionInfoSizeA#8'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:549: undefined reference to `GetFileVersionInfoA#16'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:550: undefined reference to `VerQueryValueA#16'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `UILess_GetCandidateList':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:966: undefined reference to `_imp__SysFreeString#4'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:662: undefined reference to `ImmGetContext#4'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:666: undefined reference to `ImmNotifyIME#16'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:670: undefined reference to `ImmNotifyIME#16'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:671: undefined reference to `ImmReleaseContext#8'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Disable':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:344: undefined reference to `ImmAssociateContext#8'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:668: undefined reference to `ImmSetCompositionStringW#24'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:662: undefined reference to `ImmGetContext#4'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:666: undefined reference to `ImmNotifyIME#16'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:670: undefined reference to `ImmNotifyIME#16'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:671: undefined reference to `ImmReleaseContext#8'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:668: undefined reference to `ImmSetCompositionStringW#24'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `UIElementSink_BeginUIElement#12':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:1033: undefined reference to `_imp__SysFreeString#4'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `UIElementSink_UpdateUIElement#8':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:1060: undefined reference to `_imp__SysFreeString#4'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Init':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:289: undefined reference to `_imp__CoCreateInstance#20'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:303: undefined reference to `ImmGetContext#4'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:304: undefined reference to `ImmReleaseContext#8'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `UILess_SetupSinks':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:1174: undefined reference to `_imp__CoCreateInstance#20'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetId':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:530: undefined reference to `ImmGetIMEFileNameA#12'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:545: undefined reference to `GetFileVersionInfoSizeA#8'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:549: undefined reference to `GetFileVersionInfoA#16'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetReadingString':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:402: undefined reference to `ImmGetContext#4'
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:477: undefined reference to `ImmReleaseContext#8'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetId':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:550: undefined reference to `VerQueryValueA#16'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Quit':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:358: undefined reference to `ImmAssociateContext#8'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Enable':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:329: undefined reference to `ImmAssociateContext#8'
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition':
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:662: undefined reference to `ImmGetContext#4'
Process terminated with status 1 (0 minute(s), 0 second(s))
50 error(s), 0 warning(s) (0 minute(s), 0 second(s))
This does not happen when linking a normal Wolf4SDL mod (which uses SDL 1.2), and it links correctly if I don't use -static but then won't run without various other DLLs being present (namely libgcc_s_dw2-1.dll and the like). While I can just change PATH to include my MinGW directory, when it comes time to distribute it I can't expect everyone to have MinGW installed, and I want to keep the number of DLLs I'm distributing with my mod to a minimum considering I'm already using SDL_mixer and SDL_image which come with a ton of DLLs already. Anyone have a solution to this?
OK, fixed the problem - I needed to link a variety of Windows libraries, namely Ole32, Oleaut32, Imm32, Winmm and Version. Not sure why this wasn't the case for SDL 1; it wasn't mentioned in the Migration Guide either so I'm not sure where the difference comes from.
For me this meant "use pkg-config --static" since I had compiled a static only version and wanted to use that.
Guess that's just how pkg-config rolls.
Another option (like the OP mentioned) is to either add the libraries you need "out of band" or to modify sdl2.pc so it includes "all the libraries you need" on the Libs: line (not Libs.static: line which probably already has them).
Again, that's how pkg-config rolls :|
I am trying to compile a very simple OpenGL program that uses GLFW3. Despite linking everything I deem necessary, I'm getting a plethora of undefined references.
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwInitGammaRamp':
x11_gamma.c:(.text+0x49): undefined reference to `XRRGetScreenResources'
x11_gamma.c:(.text+0x6a): undefined reference to `XRRGetCrtcGammaSize'
x11_gamma.c:(.text+0x81): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwPlatformGetGammaRamp':
x11_gamma.c:(.text+0xce): undefined reference to `XRRGetCrtcGammaSize'
x11_gamma.c:(.text+0xf1): undefined reference to `XRRGetCrtcGamma'
x11_gamma.c:(.text+0x198): undefined reference to `XRRFreeGamma'
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwPlatformSetGammaRamp':
x11_gamma.c:(.text+0x24c): undefined reference to `XRRAllocGamma'
x11_gamma.c:(.text+0x303): undefined reference to `XRRSetCrtcGamma'
x11_gamma.c:(.text+0x30f): undefined reference to `XRRFreeGamma'
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x1a67): undefined reference to `XRRQueryExtension'
x11_init.c:(.text+0x1a91): undefined reference to `XRRQueryVersion'
x11_init.c:(.text+0x1b25): undefined reference to `XIQueryVersion'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwSetVideoMode':
x11_monitor.c:(.text+0x177): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x19c): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x1be): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0x3d0): undefined reference to `XRRSetCrtcConfig'
x11_monitor.c:(.text+0x3dc): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x3e8): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x3f4): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwRestoreVideoMode':
x11_monitor.c:(.text+0x446): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x46b): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x4e0): undefined reference to `XRRSetCrtcConfig'
x11_monitor.c:(.text+0x4ec): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x4f8): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
x11_monitor.c:(.text+0x55a): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x577): undefined reference to `XRRGetOutputPrimary'
x11_monitor.c:(.text+0x5cf): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x5ea): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x659): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0x676): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x682): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x703): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x70f): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x733): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitorPos':
x11_monitor.c:(.text+0x8a2): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x8c7): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x8ff): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x90b): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetVideoModes':
x11_monitor.c:(.text+0x9ad): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x9cf): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0xb44): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0xb50): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetVideoMode':
x11_monitor.c:(.text+0xc28): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0xc4d): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0xca2): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0xcae): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_window.c.o): In function `createWindow':
x11_window.c:(.text+0x666): undefined reference to `XISelectEvents'
x11_window.c:(.text+0x6a8): undefined reference to `XRRSelectInput'
/usr/local/lib/libglfw3.a(x11_window.c.o): In function `processEvent':
x11_window.c:(.text+0x1711): undefined reference to `XRRUpdateConfiguration'
My linked CMake flags:
-I/usr/local/include -L/usr/local/lib -lglfw3 -lGLU -lGL -lGLEW
Should I be linking anything else?
I figured out the answer myself while writing the question.
I was misled into believing that I was linking everything necessary because of the output of
pkg-config --libs --cflags --print-requires glfw3
which was
-I/usr/local/include -L/usr/local/lib -lglfw3
The --print-requires flag was having no impact at all on the output, which seemed odd. I searched and printed the corresponding .pc file.
sudo find / | grep "glfw3\.pc"
cat /usr/local/lib/pkgconfig/glfw3.pc
There I found this.
Requires.private: x11 xrandr xi xxf86vm gl
Which indicates which libraries are required for static linking. I added their correponding flags to CMake and it worked. My mistake was that I missed the --print-requires-private flag when executing pkg-config.
I hope this helps someone save some time.
This question already has answers here:
OpenCV 2.3 Compiling Issue - Undefined Refence - Ubuntu 11.10
(4 answers)
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 9 years ago.
I have kubuntu and i've installed Opencv with the instruction
sudo apt-get install libopencv-dev
on Kubuntu 13.04.
I try to compile a program on opencv but i have this error:
berny88#berny88-VPCEB3J1E:~/Scaricati/CameraCalibration/camera_calibration/camera_calibration$ g++ -Iusr/include/opencv2 camera_calibration.cpp
/tmp/cc51xq2l.o: In function `main':
camera_calibration.cpp:(.text+0x9a): undefined reference to `cvCreateCameraCapture'
camera_calibration.cpp:(.text+0xce): undefined reference to `cvNamedWindow'
camera_calibration.cpp:(.text+0xdd): undefined reference to `cvNamedWindow'
camera_calibration.cpp:(.text+0xf8): undefined reference to `cvCreateMat'
camera_calibration.cpp:(.text+0x11a): undefined reference to `cvCreateMat'
camera_calibration.cpp:(.text+0x138): undefined reference to `cvCreateMat'
camera_calibration.cpp:(.text+0x153): undefined reference to `cvCreateMat'
camera_calibration.cpp:(.text+0x16e): undefined reference to `cvCreateMat'
camera_calibration.cpp:(.text+0x1aa): undefined reference to `cvQueryFrame'
camera_calibration.cpp:(.text+0x1c0): undefined reference to `cvGetSize'
camera_calibration.cpp:(.text+0x1d2): undefined reference to `cvCreateImage'
camera_calibration.cpp:(.text+0x225): undefined reference to `cvFindChessboardCorners'
camera_calibration.cpp:(.text+0x243): undefined reference to `cvCvtColor'
camera_calibration.cpp:(.text+0x2d4): undefined reference to `cvFindCornerSubPix'
camera_calibration.cpp:(.text+0x2fa): undefined reference to `cvDrawChessboardCorners'
camera_calibration.cpp:(.text+0x31a): undefined reference to `cvShowImage'
camera_calibration.cpp:(.text+0x61e): undefined reference to `cvShowImage'
camera_calibration.cpp:(.text+0x628): undefined reference to `cvWaitKey'
camera_calibration.cpp:(.text+0x644): undefined reference to `cvWaitKey'
camera_calibration.cpp:(.text+0x682): undefined reference to `cvQueryFrame'
camera_calibration.cpp:(.text+0x69d): undefined reference to `cvShowImage'
camera_calibration.cpp:(.text+0x6bb): undefined reference to `cvDestroyWindow'
camera_calibration.cpp:(.text+0x6dd): undefined reference to `cvCreateMat'
camera_calibration.cpp:(.text+0x6f9): undefined reference to `cvCreateMat'
camera_calibration.cpp:(.text+0x711): undefined reference to `cvCreateMat'
camera_calibration.cpp:(.text+0xba8): undefined reference to `cvReleaseMat'
camera_calibration.cpp:(.text+0xbb7): undefined reference to `cvReleaseMat'
camera_calibration.cpp:(.text+0xbc6): undefined reference to `cvReleaseMat'
camera_calibration.cpp:(.text+0xc78): undefined reference to `cvGetSize'
camera_calibration.cpp:(.text+0xcbc): undefined reference to `cvCalibrateCamera2'
camera_calibration.cpp:(.text+0xd41): undefined reference to `cvSave'
camera_calibration.cpp:(.text+0xdb2): undefined reference to `cvSave'
camera_calibration.cpp:(.text+0xde4): undefined reference to `cvLoad'
camera_calibration.cpp:(.text+0xe01): undefined reference to `cvLoad'
collect2: ld returned 1 exit status
How can resolve this problem??