在优胜美地中通过g ++链接SOIL的问题

bei*_*eis 5 c++ opengl macos soil

我一直在尝试为正在使用OpenGL的项目链接SOIL。我正在运行优胜美地10.10.4。

当我尝试在代码中使用SOIL库时,出现以下错误(已更新):

ld: warning: ignoring file /usr/local/lib/libSOIL.a, 
file was built for archive which is not the architecture being linked (x86_64): /usr/local/lib/libSOIL.a
Undefined symbols for architecture x86_64:
"_SOIL_load_image", referenced from:
  init() in main-93f615.o
ld: symbol(s) not found for architecture x86_64
Run Code Online (Sandbox Code Playgroud)

我的脚步

我遵循SOIL中make文件指示的过程:make,make install。它将libSOIL.a文件放在/ usr / local / lib中,将SOIL.h放在/ usr / local / include中。我包含在我的代码中:

#include "SOIL.h"

int width, height;
unsigned char* image = SOIL_load_image("CrayonBox2.png", &width, &height, 0, SOIL_LOAD_RGB);
Run Code Online (Sandbox Code Playgroud)

我的Makefile包含以下g ++目标:

g++ -I/usr/X11R6/include -I/usr/local/include -I/opt/local/include -L/usr/local/lib/ -L/opt/local/lib -lSOIL -framework GLUT -framework OpenGL -framework CoreFoundation -o main main.cpp
Run Code Online (Sandbox Code Playgroud)

然后出现以上错误。

然后,我尝试了许多不同的操作:我安装了Mac OS的SOIL版本(将libSOIL.a和libSOIL.dylib放在/ opt / local / lib中,将SOIL.h放在/ opt / local / include中);我尝试'-arch 1386 -arch x86_64' 按照此答案的建议添加。有了这些,我仍然会收到与以前相同的错误。

关于什么可能有什么建议?

小智 1

我也有同样的问题,我的解决方案是修改makefile,通过add -m64让gcc支持64。

另请参阅简单 OpenGL 图像库/projects/makefile/makefile:

CXXFLAGS = -O2 -s -Wall -m64

再次安装并替换libSOIL.a。

希望我的回答能够帮助到您。