5

I've been trying to link SOIL for a project I am working on with OpenGL. I'm running Yosemite 10.10.4.

When I try to use the SOIL library in my code, I get the following error (updated):

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

My Steps

I followed the process indicated by the make file in SOIL: make, make install. It placed the libSOIL.a file in /usr/local/lib and SOIL.h in /usr/local/include. I included in my code:

#include "SOIL.h"

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

And my Makefile contained this g++ target:

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

Then the above error appeared.

I then tried a number of different things: I installed this guy's version of SOIL for Mac OS (which places libSOIL.a and libSOIL.dylib in /opt/local/lib and SOIL.h in /opt/local/include); I tried adding '-arch 1386 -arch x86_64' as per this answer's suggestion. With each of these, I still receive the same error as before.

Any recommendations on what might be the issue?

Community
  • 1
  • 1
beisbeis
  • 148
  • 9

3 Answers3

1

I have the same problem, what my solution is modify the makefile, to let gcc support 64 through add -m64.

also see Simple OpenGL Image Library/projects/makefile/makefile:

CXXFLAGS = -O2 -s -Wall -m64

Make install and replace libSOIL.a again.

I hope the answer can help you.

Jihui Xu
  • 22
  • 3
0

Specify the source files before the library specifications (-l and -L):

g++ main.cpp -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

You probably want -o myexe, otherwise the output file will be a.out...

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • Thanks for that reminder. I had taken out the -o earlier because I thought it wasn't pertinent - I'll put it back in. This answer didn't fix it yet, but I'll keep this in mind. – beisbeis Sep 16 '15 at 19:00
0

You are probably using the pre-compiled static library. Better to compile SOIL for your system. A pretty common compilation pipeline is using CMake and Make. Clone https://github.com/DeVaukz/SOIL move to the downloaded directory.

mkdir build
cd build
cmake ..
make
sudo make install
rodrygojose
  • 176
  • 1
  • 6