【发布时间】:2021-02-17 04:02:50
【问题描述】:
我正在尝试静态编译一个简单的程序:
#include <iostream>
#include <vector>
#include <string>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "HW Test");
vector<string> m = {"Hello", "world"};
for (const string &msg : m) {
cout << msg;
cout << " ";
}
}
g++ 编译器标志:
C:\Users\Retsal\Documents\Cpp\SfmlTest>g++ -o hw.exe .\src\helloworld.cpp -I C:\Users\Retsal\Documents\Cpp\SfmlTest\include -DSFML_STATIC -L C:\Users\Retsal\Documents\Cpp\SfmlTest\lib -l sfml-system-s -l sfml-graphics-s -l sfml-window-s -l gdi32 -l winmm -l opengl32 -l freetype
这是 g++ 编译器产生的错误示例:
C:\Users\Retsal\Documents\Cpp\SfmlTest\lib/libsfml-graphics-s.a(Texture.cpp.obj):Texture.cpp:(.text+0x5c): undefined reference to `sf::Lock::Lock(sf::Mutex&)'
C:\Users\Retsal\Documents\Cpp\SfmlTest\lib/libsfml-graphics-s.a(Texture.cpp.obj):Texture.cpp:(.text+0x76): undefined reference to `sf::Lock::~Lock()'
C:\Users\Retsal\Documents\Cpp\SfmlTest\lib/libsfml-graphics-s.a(Texture.cpp.obj):Texture.cpp:(.text+0x16f): undefined reference to `sf::Lock::Lock(sf::Mutex&)'
C:\Users\Retsal\Documents\Cpp\SfmlTest\lib/libsfml-window-s.a(JoystickImpl.cpp.obj):JoystickImpl.cpp:(.text.startup+0x5f): undefined reference to `sf::milliseconds(int)'
C:\Users\Retsal\Documents\Cpp\SfmlTest\lib/libsfml-window-s.a(JoystickImpl.cpp.obj):JoystickImpl.cpp:(.text.startup+0x7c): undefined reference to `sf::Clock::Clock()'
collect2.exe: error: ld returned 1 exit status
(相同的输出错误:Texture.cpp.obj、RenderTextureImplFBO.cpp.obj、GLExtensions.cpp.obj、Image.cpp.obj、Shader.cpp.obj、VertexBuffer.cpp.obj、Context.cpp.obj , Window.cpp.obj, WindowBase.cpp.obj, WindowImpl.cpp.obj, WglContext.cpp.obj, WindowImplWin32.cpp.obj 和 JoystickImpl.cpp.obj)
我正在使用 mingw 版本 x86_64-8.1.0-posix-seh-rt_v6-rev0 和sfml版本windows-gcc-810-mingw-64
你知道我该怎么做才能成功静态编译吗?
提前谢谢你:)
【问题讨论】:
-
尝试将
-lsfml-system-s移到编译命令的后面。一般来说,您需要将依赖项放在依赖项之前。 -
@Botje 谢谢你的回答 :) 我试过你说的,但不幸的是它没有用。
标签: c++ windows linker mingw sfml