首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能用GCC编译SFML + ImGui

不能用GCC编译SFML + ImGui
EN

Stack Overflow用户
提问于 2022-02-14 12:01:05
回答 1查看 284关注 0票数 0

自从我开始学习SFML以来,我发现很难在CPP中包含库。

我发现最简单的两种方法是像教程一样配置Visual,或者用CLion配置CLion。

但是我不喜欢Visual,CLion在机器上真的很重,我只是无法解除CMake。

因此,我开始使用VSCode并制作.bat文件和mingw32 g++来构建和运行:

g++ ../main.cpp -o ../build/main.exe -I ${SFML_DIR}\include -L ${SFML_DIR}\lib -lsfml-graphics -lsfml-window -lsfml-system

这是我所做的构建中最简单的,考虑到.bat文件在内部,并且我希望构建位于根/构建中,并被命名为main.exe。然后我可以使用另一个.bat文件运行它:

"../build/main.exe"

但是,为了与ImGui一起编译它,我遇到了一些问题,我试着运行:

g++ ../main.cpp -o ../build/main.exe -I ${IMGUI-DIR} -L ${IMGUI-DIR} -I ${IMGUI-DIR}\backends -L ${IMGUI-DIR}\backends -I ${IMGUI-SFML-DIR} -L ${IMGUI-SFML-DIR} -I ${SFML-DIR}\include -L ${SFML-DIR}\lib -lsfml-graphics -lsfml-window -lsfml-system -lopengl32

但我总是会犯这样的错误:

对AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x12d):ImGui::SFML::ProcessEvent(sf::Event &)‘AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x2ac):未定义引用ImGui::SFML::Update(sf::RenderWindow&, sf::Time)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x2c8): undefined reference to ImGui::Begin(char const*,bool*,int)’AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x2e6):未定义引用ImGui::ColorEdit3(char const*, float*, int)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x3c1): undefined reference to ImGui::InputText( const*,char*,unsigned,int,int ()(ImGuiInputTextCallbackData),void*)‘对ImGui::Button(char const*, ImVec2 const&)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x44a): undefined reference to ImGui的未定义引用::End()’AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x476):未定义对ImGui::SFML::Render(sf::RenderWindow&)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x48f): undefined reference to ImGui的引用::SFML::ImGui::Button(char const*, ImVec2 const&)' AppData\Local\Temp\ccogESXd.o:main.cpp:(.text+0x44a): undefined reference to()

我不知道我做错了什么,如果有人有更好的方法来做这一切的建议或建议,将会被接受:)

EN

回答 1

Stack Overflow用户

发布于 2022-02-14 17:23:40

通过在项目根目录中创建一个名为"include“的文件夹,将imgui和imgui的所有.h和.cpp文件放入其中,并运行以下3行命令,它对我起了作用:

g++ -c ../include /*..cpp./ -L ./include -I C:\SFML\ g++ C:\SFML\lib -lsfml-graphics -lsfml-window -lsfml-system -lopengl32 g++ -c ./main.cpp -I ./include -I C:\SFML\g++C:\SFML\graphics:\SFML lsfml-窗口-lsfml-system -lopengl32 g++ *.o -o ./build/main。exe -I C:\SFML\包括-L C:\SFML\lib -lsfml--L -lsfml-window -lsfml-system -lopengl32

感谢@drescherjm的评论,它真的帮助了我!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71111556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档