与 glfw3 链接时出错
Error occurs when linking with glfw3
我一直在尝试编译C++代码,最近不依赖IDE,我决定使用编辑器和命令行来编写和编译代码。
问题是我想制作一个 glfw 应用程序,但在与 glfw3.lib 和 opengl32.lib 链接时出现错误:
A.exe:致命错误 LNK1120:92 个未解析的外部
操作系统: 视窗 7
编译器:叮当
src/main.cpp:
#include <stdlib.h>
#include <stdio.h>
#include "window.h"
#define WIDTH 800
#define HEIGHT 600
int main(int argc, char* argv[]){
if (!Window_init(WIDTH, HEIGHT, "HELLOWORLD")){
printf("Problem loading window!n");
return 1;
}
return 0;
}
src/window.h
#ifndef WINDOW_H
#define WINDOW_H
#include "GLFW/glfw3.h"
#define GLFW_INCLUDE_NONE
static GLFWwindow* window;
int Window_init(int width, int height, char* title);
void Window_update();
int Window_init(int width, int height, char* title){
if (!glfwInit())return 0;
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
window = glfwCreateWindow(width, height, title,NULL, NULL);
if (!window){
return 0;
}
glfwMakeContextCurrent(window);
return 1;
}
void Window_update(){
}
#endif // !WINDOW_H
编译命令:
clang++ ..src*.cpp ..src*.h -L..lib -lglfw3 -lopengl32 -I..include -std=c++17
错误:
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
glfw3.lib(init.c.obj) : warning LNK4217: locally defined symbol ___stdio_common_vsprintf imported in function __glfwInputError
glfw3.lib(wgl_context.c.obj) : warning LNK4049: locally defined symbol _free imported
glfw3.lib(egl_context.c.obj) : warning LNK4217: locally defined symbol _free imported in function __glfwInitEGL
glfw3.lib(monitor.c.obj) : warning LNK4049: locally defined symbol _free imported
glfw3.lib(vulkan.c.obj) : warning LNK4049: locally defined symbol _free imported
glfw3.lib(win32_window.c.obj) : warning LNK4049: locally defined symbol _free imported
glfw3.lib(win32_joystick.c.obj) : warning LNK4217: locally defined symbol _free imported in function _pollJoystickState
glfw3.lib(window.c.obj) : warning LNK4217: locally defined symbol _free imported in function _glfwDestroyWindow
glfw3.lib(input.c.obj) : warning LNK4217: locally defined symbol _free imported in function _glfwSetInputMode
glfw3.lib(win32_init.c.obj) : warning LNK4049: locally defined symbol _free imported
glfw3.lib(win32_monitor.c.obj) : warning LNK4049: locally defined symbol _free imported
glfw3.lib(monitor.c.obj) : warning LNK4217: locally defined symbol _qsort imported in function _refreshVideoModes
glfw3.lib(win32_joystick.c.obj) : warning LNK4049: locally defined symbol _qsort imported
glfw3.lib(wgl_context.c.obj) : error LNK2001: unresolved external symbol __imp__calloc
glfw3.lib(egl_context.c.obj) : error LNK2001: unresolved external symbol __imp__calloc
glfw3.lib(monitor.c.obj) : error LNK2001: unresolved external symbol __imp__calloc
glfw3.lib(vulkan.c.obj) : error LNK2001: unresolved external symbol __imp__calloc
glfw3.lib(win32_window.c.obj) : error LNK2001: unresolved external symbol __imp__calloc
glfw3.lib(win32_joystick.c.obj) : error LNK2001: unresolved external symbol __imp__calloc
glfw3.lib(window.c.obj) : error LNK2001: unresolved external symbol __imp__calloc
glfw3.lib(input.c.obj) : error LNK2001: unresolved external symbol __imp__calloc
glfw3.lib(win32_init.c.obj) : error LNK2001: unresolved external symbol __imp__calloc
glfw3.lib(win32_monitor.c.obj) : error LNK2001: unresolved external symbol __imp__calloc
glfw3.lib(context.c.obj) : error LNK2019: unresolved external symbol __imp__strstr referenced in function __glfwStringInExtensionString
glfw3.lib(win32_joystick.c.obj) : error LNK2001: unresolved external symbol __imp__strstr
glfw3.lib(context.c.obj) : error LNK2019: unresolved external symbol __imp__strncmp referenced in function __glfwRefreshContextAttribs
glfw3.lib(egl_context.c.obj) : error LNK2001: unresolved external symbol __imp__strncmp
glfw3.lib(context.c.obj) : error LNK2019: unresolved external symbol __imp____stdio_common_vsscanf referenced in function __vsscanf_l
glfw3.lib(win32_init.c.obj) : error LNK2019: unresolved external symbol __imp__RegisterDeviceNotificationW@12 referenced in function _createHelperWindow
glfw3.lib(win32_init.c.obj) : error LNK2019: unresolved external symbol __imp__CreateWindowExW@48 referenced in function _createHelperWindow
glfw3.lib(win32_window.c.obj) : error LNK2001: unresolved external symbol __imp__CreateWindowExW@48
glfw3.lib(win32_init.c.obj) : error LNK2019: unresolved external symbol __imp__DestroyWindow@4 referenced in function __glfwPlatformTerminate
glfw3.lib(win32_window.c.obj) : error LNK2001: unresolved external symbol __imp__DestroyWindow@4
glfw3.lib(win32_init.c.obj) : error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function _createHelperWindow
glfw3.lib(win32_window.c.obj) : error LNK2001: unresolved external symbol __imp__ShowWindow@8
glfw3.lib(win32_init.c.obj) : error LNK2019: unresolved external symbol __imp__SystemParametersInfoW@16 referenced in function __glfwPlatformInit
glfw3.lib(win32_monitor.c.obj) : error LNK2019: unresolved external symbol __imp__CreateDCW@16 referenced in function __glfwPlatformGetGammaRamp
glfw3.lib(win32_monitor.c.obj) : error LNK2019: unresolved external symbol __imp__DeleteDC@4 referenced in function __glfwPlatformGetGammaRamp
glfw3.lib(win32_monitor.c.obj) : error LNK2019: unresolved external symbol __imp__GetDeviceCaps@8 referenced in function _createMonitor
glfw3.lib(win32_monitor.c.obj) : error LNK2019: unresolved external symbol __imp__GetDeviceGammaRamp@8 referenced in function __glfwPlatformGetGammaRamp
glfw3.lib(win32_monitor.c.obj) : error LNK2019: unresolved external symbol __imp__SetDeviceGammaRamp@8 referenced in function __glfwPlatformSetGammaRamp
glfw3.lib(win32_monitor.c.obj) : error LNK2019: unresolved external symbol __imp__ChangeDisplaySettingsExW@20 referenced in function __glfwPlatformGetVideoModes
glfw3.lib(win32_monitor.c.obj) : error LNK2019: unresolved external symbol __imp__EnumDisplaySettingsW@12 referenced in function __glfwPlatformGetVideoMode
glfw3.lib(win32_monitor.c.obj) : error LNK2019: unresolved external symbol __imp__EnumDisplaySettingsExW@16 referenced in function __glfwPlatformGetMonitorPos
glfw3.lib(win32_monitor.c.obj) : error LNK2019: unresolved external symbol __imp__EnumDisplayDevicesW@16 referenced in function __glfwPlatformGetMonitors
glfw3.lib(win32_monitor.c.obj) : error LNK2019: unresolved external symbol __imp__realloc referenced in function __glfwPlatformGetMonitors
glfw3.lib(monitor.c.obj) : error LNK2019: unresolved external symbol __imp___strdup referenced in function __glfwAllocMonitor
glfw3.lib(win32_window.c.obj) : error LNK2001: unresolved external symbol __imp___strdup
glfw3.lib(win32_joystick.c.obj) : error LNK2001: unresolved external symbol __imp___strdup
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__CreateBitmap@20 referenced in function _createIcon
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__DeleteObject@4 referenced in function _createIcon
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__CreateDIBSection@24 referenced in function _createIcon
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__TrackMouseEvent@4 referenced in function _windowProc@16
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__TranslateMessage@4 referenced in function __glfwPlatformPollEvents
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__DispatchMessageW@4 referenced in function __glfwPlatformPollEvents
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__PeekMessageW@20 referenced in function __glfwPlatformPollEvents
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetMessageTime@0 referenced in function _translateKey
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SendMessageW@16 referenced in function __glfwPlatformSetWindowIcon
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__PostMessageW@16 referenced in function __glfwPlatformPostEmptyEvent
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__WaitMessage@0 referenced in function __glfwPlatformWaitEvents
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__DefWindowProcW@16 referenced in function _windowProc@16
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__UnregisterClassW@8 referenced in function __glfwUnregisterWindowClassWin32
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__RegisterClassExW@4 referenced in function __glfwRegisterWindowClassWin32
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__MoveWindow@24 referenced in function __glfwPlatformSetWindowAspectRatio
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SetWindowPos@28 referenced in function __glfwPlatformSetWindowMonitor
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__IsWindowVisible@4 referenced in function __glfwPlatformWindowVisible
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__IsIconic@4 referenced in function __glfwPlatformWindowIconified
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__BringWindowToTop@4 referenced in function __glfwPlatformCreateWindow
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__IsZoomed@4 referenced in function __glfwPlatformWindowMaximized
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__OpenClipboard@4 referenced in function __glfwPlatformGetClipboardString
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__CloseClipboard@0 referenced in function __glfwPlatformGetClipboardString
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SetClipboardData@8 referenced in function __glfwPlatformSetClipboardString
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetClipboardData@4 referenced in function __glfwPlatformGetClipboardString
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__EmptyClipboard@0 referenced in function __glfwPlatformSetClipboardString
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SetFocus@4 referenced in function __glfwPlatformCreateWindow
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetActiveWindow@0 referenced in function __glfwPlatformPollEvents
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetKeyState@4 referenced in function _getKeyMods
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetAsyncKeyState@4 referenced in function __glfwPlatformPollEvents
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetKeyNameTextW@12 referenced in function __glfwPlatformGetKeyName
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SetCapture@4 referenced in function _windowProc@16
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__ReleaseCapture@0 referenced in function _windowProc@16
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__MsgWaitForMultipleObjects@20 referenced in function __glfwPlatformWaitEventsTimeout
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetSystemMetrics@4 referenced in function __glfwPlatformSetWindowIcon
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SetForegroundWindow@4 referenced in function __glfwPlatformCreateWindow
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetDC@4 referenced in function _createIcon
glfw3.lib(wgl_context.c.obj) : error LNK2001: unresolved external symbol __imp__GetDC@4
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__ReleaseDC@8 referenced in function _createIcon
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SetPropW@12 referenced in function _createNativeWindow
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetPropW@8 referenced in function __glfwPlatformPollEvents
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__RemovePropW@8 referenced in function __glfwPlatformDestroyWindow
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SetWindowTextW@8 referenced in function __glfwPlatformSetWindowTitle
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetClientRect@8 referenced in function __glfwPlatformGetFramebufferSize
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetWindowRect@8 referenced in function __glfwPlatformSetWindowAspectRatio
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__AdjustWindowRectEx@16 referenced in function __glfwPlatformGetWindowFrameSize
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SetCursorPos@8 referenced in function __glfwPlatformPollEvents
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SetCursor@4 referenced in function __glfwPlatformSetCursor
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetCursorPos@4 referenced in function __glfwPlatformGetCursorPos
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__ClipCursor@4 referenced in function __glfwPlatformSetCursorMode
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__ClientToScreen@8 referenced in function __glfwPlatformGetWindowPos
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__ScreenToClient@8 referenced in function __glfwPlatformGetCursorPos
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__WindowFromPoint@8 referenced in function _cursorInClientArea
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SetRect@20 referenced in function __glfwPlatformGetWindowFrameSize
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__PtInRect@12 referenced in function _cursorInClientArea
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetWindowLongW@8 referenced in function __glfwPlatformSetWindowMonitor
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__SetWindowLongW@12 referenced in function __glfwPlatformSetWindowMonitor
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__GetClassLongW@8 referenced in function __glfwPlatformSetWindowIcon
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__LoadCursorW@8 referenced in function __glfwPlatformCreateStandardCursor
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__DestroyIcon@4 referenced in function __glfwPlatformDestroyCursor
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__LoadImageW@24 referenced in function __glfwRegisterWindowClassWin32
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__CreateIconIndirect@4 referenced in function _createIcon
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__CopyIcon@4 referenced in function __glfwPlatformCreateStandardCursor
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__DragQueryFileW@16 referenced in function _windowProc@16
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__DragQueryPoint@8 referenced in function _windowProc@16
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__DragFinish@4 referenced in function _windowProc@16
glfw3.lib(win32_window.c.obj) : error LNK2019: unresolved external symbol __imp__DragAcceptFiles@8 referenced in function _createNativeWindow
glfw3.lib(win32_joystick.c.obj) : error LNK2019: unresolved external symbol __imp__GetRawInputDeviceInfoA@16 referenced in function _supportsXInput
glfw3.lib(win32_joystick.c.obj) : error LNK2019: unresolved external symbol __imp__GetRawInputDeviceList@12 referenced in function _supportsXInput
glfw3.lib(wgl_context.c.obj) : error LNK2019: unresolved external symbol __imp__ChoosePixelFormat@8 referenced in function _loadWGLExtensions
glfw3.lib(wgl_context.c.obj) : error LNK2019: unresolved external symbol __imp__DescribePixelFormat@16 referenced in function __glfwCreateContextWGL
glfw3.lib(wgl_context.c.obj) : error LNK2019: unresolved external symbol __imp__SetPixelFormat@12 referenced in function __glfwCreateContextWGL
glfw3.lib(wgl_context.c.obj) : error LNK2019: unresolved external symbol __imp__SwapBuffers@4 referenced in function _swapBuffersWGL
MSVCRT.lib(_chandler4gs_.obj) : error LNK2019: unresolved external symbol __except_handler4_common referenced in function __except_handler4
a.exe : fatal error LNK1120: 92 unresolved externals
clang++.exe: error: linker command failed with exit code 1120 (use -v to see invocation)
让我们演示一下算法。
- 让我们看到未解析符号之间的
__imp__GetRawInputDeviceInfoA
。 - 谷歌
GetRawInputDeviceInfoA
. - 结果的第一页是 https://msdn.microsoft.com/en-us/library/windows/desktop/ms645597(v=vs.85(.aspx
- 打开页面并将其滚动到底部。我们看到那里
| Library | User32.lib |
. - 将库添加到命令行:
clang++ ..src*.cpp -L..lib -lglfw3 -lopengl32 -I..include -std=c++17 User32.lib
- 尝试构建。
- 从 1 到 6 重复,直到修复所有未解析的符号。
从命令行中删除..src*.h
。
相关文章:
- 读取文件的最后一行并输入到链接列表时出错
- C++ 创建包含链表和字符串的对象的链接列表时出错
- 在发布模式下启动使用库的静态链接编译的应用程序时出错
- 编译时出错 - 链接.cpp和头文件
- 将 boost 与 Visual Studio 和 vcpkg 链接时出错
- 获取链接 创建flyweight_pattern时出错
- 从Qt5链接MySQL时出错
- 迭代器关系运算符出错(带单独链接和迭代器的自定义哈希表)
- 与 glfw3 链接时出错
- GNU 链接器:如果头文件中的指针被声明为 NULL 和/或 extern,则出错
- 可能的 GCC 链接器错误会导致将弱符号和局部符号链接在一起时出错
- 使用提升库和 clion 链接时出错
- 在 Fedora 27 中构建 GLFW 时链接期间出错
- 将 CLANG 构建的可执行文件与 G++-v6 构建的 Boost 库链接时出错
- 链接 gtest 项目时出错
- 链接webrtc本机时出错,因为未定义对具有std::string的方法的引用
- wxwidget 3.1.2 代码块 17.04 在链接步骤中出错
- 链接Firebase C (分析)库时出错
- 在Windows上使用GCC的链接时间优化构建wxWidgets DLL时出错
- 生成mpi2时出错-链接libboost_system时出错