Monday, April 10, 2017

Linking the wrong library version of SOIL into an OpenGL Project

Here's a summary of what I wrote. I admit I wrote a lot for this one:

Tips on linking:

1. Know if your errors are linking errors. In Visual Studio 2015, as shown above, the errors usually come up with code numbers starting with LNK, like "LNK2001" or "LNK1120". If you know how to solve the linking errors, work from there.

2. One of the ways to solve a linking error is to have the correct bit version of the library linked in a given build. It's either 32-bit or 64-bit.


Compiling SOIL on VS 2015:

The lib/libSOIL.a library file given in the SOIL folder download doesn't work for me. I opened the VC9 .sln in projects/VC9, and built my own 32 and 64-bit SOIL.lib files instead.

------------------------------------

When I originally did the Texture tutorial on the Learn OpenGL site, I did it in 64-bit on Windows 8.1, on Visual Studio 14 (aka Visual Studio 2015). Later, when I was doing the Model tutorial also on Learn OpenGL, I ran into some .dll issues where the .exe was crashing w/ no C++ or GLSL errors. I thought using 32-bit libraries would fix it. (It didn't. I had to change power settings to High Performance. I'll write about that in a future post).

After I compiled 32-bit libraries, moved them to a new folder, and linked them to my project, for some reason I placed a 64-bit library version of SOIL.lib into my libraries folder. To make sure everything was working, I tried to do a Release build on 32-bit  (Release | x86 in the pic below). I got linking errors.




Either it took me a while to see that these were linking errors, or it took me a while to figure out it was a 32-bit vs. 64-bit "wrong library version" issue. Anyways, after a while, I figured out it was a wrong library bit version. After that, it was just compiling an actual 32-bit SOIL.lib, and putting it in the right library folder.

Anyways, I thought I'd write this to say two tips that I think would help others if they get the same library error while doing the Texture tutorial :

1. Know if your errors are linking errors. In Visual Studio 2015, as shown above, the errors usually come up with code numbers starting with LNK, like "LNK2001" or "LNK1120". If you know how to solve the linking errors, work from there.

2. One of the ways to solve a linking error is to have the correct bit version of the library linked in a given build. It's either 32-bit or 64-bit.



I also thought it'd be helpful to show how I ended up building a SOIL.lib for both 32-bit and 64-bit. Learn OpenGL again has a very nice tutorial on cmake and building libraries. SOIL goes past the cmake step and already gives you projects to build libraries from. It's that small of a difference, and the Texture tutorial even points it out. But I thought I'd still show some pics on Visual Studio 2015.

1. When you download SOIL, you'll get a zip file container one folder. Extract that folder somewhere, like your desktop. Here's the SOIL site. The zip file is under the "Download" section.

2. When you open the folder, you'll see this (at least, this is what it looks like when I wrote this).

In the lib folder, there is a libSOIL.a file. That's apparently a library file too. Like it's the exact same as SOIL.lib. According to the SOIL site, it should've worked as a linked library. It didn't for me. Maybe it's not for VS 2015, but an older VS.

Anyways, if it could work for you, I'd say you can either keep the name, or rename it to something like SOIL.lib or SOIL.a ("libSOIL" or "SOIL", it doesn't matter, just make sure to update your linker settings to match the name).


3. Instead of using the lib/libSOIL.a library file (I mention my experience w/ it above), go to the projects folder. For VS 2015, I went to the VC9 folder, the latest one. Then I opened the .sln file. Then change the version settings to Win32 or x64, and build the corresponding 32-bit or 64-bit of the solution. I'd say out of whim that building on Release seems better than Debug mode.

Though Debug or Release version shouldn't matter. I'm not sure if there's a huge difference. I've noticed in both the 32 and 64 bit builds that the Debug build's libraries are smaller than the Release build's libraries.

4. Find the .lib file, copy to your libraries folder as needed, link it to your project, and you're good to go. Here's the directories that came out for me. These all start from the VC9 folder:

32-bit:
Debug: Debug
Release: Release

64-bit:
Debug: x64/Debug
Release: x64/Release

Anyways, that's my experience with SOIL. Hope it helps someone! : )