I have a project I am trying to add google-test unit testing to. It is structured like so:
VM (project)
some source files
BytecodePrograms.h
VMTest (project, made by add project -> google test -> link dynamically, test VM)
pch.h
test.cpp
I added my VM project as an include directory in VMTest properties -> c/c++ -> general -> additional include directories
contents of test.cpp are:
#include "pch.h"
#include "BytecodePrograms.h"
TEST(TestCaseName, TestName) {
EXPECT_EQ(8, VMFibonacciImp(6));
EXPECT_TRUE(true);
}
If I build, I get the following errors
Error LNK2019 unresolved external symbol "public: __thiscall WVM::WVM(void)" (??0WVM##QAE#XZ) referenced in function "int __cdecl VMFibonacciImp(int)" (?VMFibonacciImp##YAHH#Z) WVMTest C:\Users\WadeMcCall\source\repos\Virtual Machine Visual Scripting\WVMTest\test.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall WVM::~WVM(void)" (??1WVM##QAE#XZ) referenced in function "int __cdecl VMFibonacciImp(int)" (?VMFibonacciImp##YAHH#Z) WVMTest C:\Users\WadeMcCall\source\repos\Virtual Machine Visual Scripting\WVMTest\test.obj 1
Error LNK2019 unresolved external symbol "public: int __thiscall WVM::interpret(class std::vector<int,class std::allocator<int> >)" (?interpret#WVM##QAEHV?$vector#HV?$allocator#H#std###std###Z) referenced in function "int __cdecl VMFibonacciImp(int)" (?VMFibonacciImp##YAHH#Z) WVMTest C:\Users\WadeMcCall\source\repos\Virtual Machine Visual Scripting\WVMTest\test.obj 1
However, my VM project defines my WVM class and uses it and can build and run and BytecodePrograms.h includes VM.h which has the declaration for this class.
I feel like this must just be a problem with the set up of my projects in Visual Studio somehow, but I have no idea. I have been googling for 2 days straight and have found other people with similar problems but their solution never seems to work for me.
Any ideas? Thanks.
I found a solution here: https://stackoverflow.com/a/19709712/8488701
Similar to what Steve suggested, except instead of creating a whole new project, I use a post-build event to build my project to a library and then link google test to that. The advantage of this over Steve's solution is that you don't have to modify your main project at all and you can still build a unit testing project on top of it.
This is a link error indicating that it found the .h file but couldn't find the actual implementation found in the .cpp. If you have a LIB project then visual studio may take the cpp code compiled into the LIB project and add it to your EXE project.
To incorporate the code into the test project, you have two options.
You can add the .cpp files in your VM Project to your Test project as well, but this is not usually done.
Instead, if your VM project is now an EXE I would recommend creating a new project called VMLib as a LIB project and then adding that project to both the test project and the VM EXE project.
Related
I'm currently using Microsoft Unit Testing Framework for C++ and have been following this guide:
https://learn.microsoft.com/en-us/visualstudio/test/writing-unit-tests-for-c-cpp?view=vs-2019
However, when trying to create a test project under the same solution as the project I am testing I can't I keep getting the linker error
LNK2019 unresolved external symbol "public: void __cdecl SLL<int>::add(int)" (?add#?$SLL#H##QEAAXH#Z) referenced in function "public: void __cdecl A1272UnitTest::A1272UnitTest::TestMethod1(void)" (?TestMethod1#A1272UnitTest#1#QEAAXXZ)
The problem I am trying to use a method definition inside of the "q1a.cpp" file under the project I am testing.
I have tried following this guide
https://learn.microsoft.com/en-us/visualstudio/test/how-to-use-microsoft-test-framework-for-cpp?view=vs-2019#object_files
In order to link the obj files but it was of no avail.
This is what my
solution directory looks like
I want to unit test my C++ project with Visual Studio. After adding the folders from my project as include path to my test project, I get linker errors when trying to compile the tests:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __thiscall Piece::Piece(enum Color)" (??0Piece##QAE#W4Color###Z) referenced in function "public: __thiscall Bishop::Bishop(enum Color)" (??0Bishop##QAE#W4Color###Z) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall Board::~Board(void)" (??1Board##QAE#XZ) referenced in function "public: void __thiscall ChessPlusPlusTests::BishopTests::ValidMovesTest(void)" (?ValidMovesTest#BishopTests#ChessPlusPlusTests##QAEXXZ) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1
Error LNK2019 unresolved external symbol "public: void __thiscall Board::placePieceAt(class Piece * const,struct Position)" (?placePieceAt#Board##QAEXQAVPiece##UPosition###Z) referenced in function "public: void __thiscall ChessPlusPlusTests::BishopTests::ValidMovesTest(void)" (?ValidMovesTest#BishopTests#ChessPlusPlusTests##QAEXXZ) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1
Error LNK2001 unresolved external symbol "public: virtual class std::vector<struct Position,class std::allocator<struct Position> > __thiscall Bishop::getMovesFor(struct Position,class Board &)" (?getMovesFor#Bishop##UAE?AV?$vector#UPosition##V?$allocator#UPosition###std###std##UPosition##AAVBoard###Z) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1
Error LNK2001 unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Bishop::toString(void)" (?toString#Bishop##UAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1
Error LNK2001 unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall Bishop::toShortString(void)" (?toShortString#Bishop##UAE?AV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##XZ) ChessPlusPlus-Tests D:\Documents\Projects\ChessPlusPlus\ChessPlusPlus-Tests\BishopTests.obj 1
My test source code:
#include "stdafx.h"
#include "CppUnitTest.h"
#include "Bishop.h"
#include "Board.h"
#include "TestUtils.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace ChessPlusPlusTests
{
TEST_CLASS(BishopTests)
{
public:
TEST_METHOD(ValidMovesTest)
{
// Arrange
Board board{};
Bishop *piece = new Bishop{ Color::WHITE };
Position pos{ 3,3 };
board.placePieceAt(piece, pos);
// Act
auto validPositions = piece->getMovesFor(pos, board);
// Assert
TestUtils::AssertPositions(validPositions, {
0,0,0,0,0,0,0,1,
1,0,0,0,0,0,1,0,
0,1,0,0,0,1,0,0,
0,0,1,0,1,0,0,0,
0,0,0,0,0,0,0,0,
0,0,1,0,1,0,0,0,
0,1,0,0,0,1,0,0,
1,0,0,0,0,0,1,0,
});
}
};
}
Without adding the include path's the test project doesn't compile, since the header file includes in the main project rely on the include paths.
The main project compiles just fine.
Can someone help me to understand whats going wrong?
Thanks!
I believe the chosen answer is not correct. Tests typically should be run in their environment; therefore, they should not access the implementation (.cpp)
When you create a separate Test Project on Visual Studio (VS 2017) you need to create a reference to the project you want to test (right-click test project -> Add -> Reference -> tick projects):
Add a reference
If you see some linker errors, right-click from the Unit test project: Project->Linker->Input->Additional Dependencies->Edit
then add the path to your .obj files.
You could try something like "$(SolutionDir)ConsoleApplication1\$(IntDir)*.obj" where ConsoleApplication1 is the target project name.
Path to .obj
Initially, I only wanted to put a comment on Cornelis' post, but I couldn't.
https://www.codeproject.com/Tips/1085171/How-To-Do-Unit-Testing-with-Cplusplus-in-Visual-St
I found there that you have to add your .h and .cpp files as existing files also to the test project. That is left out on the official documentation or I missed it.
Now it works!
I just ran into the same problem and solved it differently, following this piece of Microsoft documentation: https://learn.microsoft.com/nl-nl/visualstudio/test/unit-testing-existing-cpp-applications-with-test-explorer?view=vs-2015&redirectedfrom=MSDN#objectRef
This solution is a bit cleaner, I think, as you don't end up with all the header files from your projects under test also showing up in your test project.
Lines from the documentation in italics, bold lines are my additions:
If the code under test does not export the functions that you want to test, you can add the output .obj or .lib file to the dependencies of the test project.
Create a C++ test project.
On the File menu, choose New, Project, Visual C++, Test, C++ Unit Test Project.
Make sure to add the projects that you want to test as References. If you forgot, you can also add these references later, in the Solution Explorer window.
In Solution Explorer, on the shortcut menu of the test project, choose Properties. The project properties window opens.
Choose Configuration Properties, Linker, Input, Additional Dependencies.
Choose Edit, and add the names of the .obj or .lib files. Do not use the full path names.
For me, there were only .obj files. I found them in the Intermediates folder, of which there are multiple versions, one for each combination of Solution Platform (x86 or x64) and Solution Configuration (Debug or Release). If you have a lot of .obj (or .lib) files, I found it convenient to open a terminal and run ls (or dir) to get the filenames, edit out the .log, .txt and .pdb filenames that I didn't need, and copy paste the list of .obj filenames into Visual Studio. For convenient editing, note that you can click on the dropdown arrow on the right hand side of the Additional Dependencies entry field and click on edit.
Choose Configuration Properties, Linker, General, Additional Library Directories.
Choose Edit, and add the directory path of the .obj or .lib files. The path is typically within the build folder of the project under test.
For me, I only had .obj files. I found them in the Intermediates folder, of which there are multiple versions, one for each combination of Solution Platform (x86 or x64) and Solution Configuration (Debug or Release). A convenient macro for setting this path for all 4 combinations is this: $(SolutionDir)bin\$(PlatformTarget)\$(IntermediateOutputPath)Intermediates. You might have to take out the bin\ part, as I have also seen the output folders set up directly in the Solution Directory, instead of in a separate binary folder.
Choose Configuration Properties, VC++ Directories, Include Directories.
Choose Edit, and then add the header directory of the project under test.
For this directory, it's okay to point directly to folders that are part of the project under test. There is no need to copy the header files over to the test project. It's also okay if this directory contains more than just the headers. For example, my source folder contains both the .h files and the .cpp files.
After following these steps, I was able to include the header files in my test code by simply writing:
#include "SomeHeaderName.h"
So, without any need to specify the folders that the header files are in.
Make sure to clean and rebuild your entire solution. Then, your tests should be able to access the functionality of the projects that you are testing.
I installed and integrated latest version of vcpkg:
e:\work\vcpkg>vcpkg version
Vcpkg package management program version 0.0.65-692a363701156f1bc319306fbde93fb6748325f6
See LICENSE.txt for license information.
e:\work\vcpkg>vcpkg integrate install
Applied user-wide integration for this vcpkg root.
All C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.
I installed google test:
e:\work\vcpkg>vcpkg list
gtest:x64-windows 1.8 GoogleTest and GoogleMock testing frameworks.
gtest:x86-windows 1.8 GoogleTest and GoogleMock testing frameworks.
I included gtest.h in my project in Visual Studio 2015 Update 3:
#include <gtest/gtest.h>
It compiles fine, but I have linker errors:
1>main.obj : error LNK2001: unresolved external symbol "void __cdecl testing::InitGoogleTest(int *,char * *)" (?InitGoogleTest#testing##YAXPEAHPEAPEAD#Z)
1>main.obj : error LNK2001: unresolved external symbol "public: int __cdecl testing::UnitTest::Run(void)" (?Run#UnitTest#testing##QEAAHXZ)
1>main.obj : error LNK2001: unresolved external symbol "public: static class testing::UnitTest * __cdecl testing::UnitTest::GetInstance(void)" (?GetInstance#UnitTest#testing##SAPEAV12#XZ)
Apparently, Visual Studio does not know it should link with gtest.lib. And I cannot understand why. Vcpkg only says that "Linking will be handled automatically." No idea how it is going to do this.
In "Additional Library Dependencies" of my project I can see these inherited values:
$(VcpkgRoot)lib
$(VcpkgRoot)lib\manual-link
And $(VcpkgRoot) is resolved to e:\work\vcpkg\installed\x64-windows\. So it seems like integration was successful. But how Visual Studio knows it should link with gtest.lib?
Note that if I add gtest.lib to "Additional Dependencies" manually, all works fine, and gtest.dll is automatically copied to output directory.
I think that the autolinking behavior has been intentionally disabled for gtest, see vcpkg issue #306.
Original comment on the issue: here.
The vcpkg implementation requires manual linking because Google Test can redefine main(), and the gtest functionality is duplicated in all of the four separate library files.
Official documentation.
The required per project configuration:
In: Configuration Properties > Linker > Input > Additional Dependencies
For release-builds:
$(VcpkgRoot)lib\manual-link\gtest_main.lib
For debug-builds:
$(VcpkgRoot)debug\lib\manual-link\gtest_main.lib
If you want to create your own custom main(), replace gtest_main.lib with gtest.lib.
If you want to use gmock, you can replace it with gmock_main.lib or gmock.lib.
This is an old thread but I would like to point out what I've found.
You need to link the libs in the manual-link directory, but you need to link them in the right order.
First link gmock_main then gtest_main.
The other way around just results in 0 test.
Just quickly before I start, I have searched SO and Google for a length of time trying to solve this and have been unsuccessful.
I am trying to compile my project, which used to use a certain library for providing GUI functionality based on Windows Forms. Now my company has started to move to Qt, and I decided I would start to convert my small application to support Qt also.
At first it would not compile at all, due to missing headers. Now that is sorted, I am stuck with my final .exe not being able to link due to the following errors.
Creating library Bin\VS_V8\Win32\Debug\Disp.lib and object Bin\VS_V8\Win32\Debug\Disp.exp
QtMainMenu.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QtMainMenu::metaObject(void)const " (?metaObject#QtMainMenu##UBEPBUQMetaObject##XZ)
QtMainMenu.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall QtMainMenu::qt_metacast(char const *)" (?qt_metacast#QtMainMenu##UAEPAXPBD#Z)
QtMainMenu.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall QtMainMenu::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#QtMainMenu##UAEHW4Call#QMetaObject##HPAPAX#Z)
Bin\VS_V8\Win32\Debug\Disp.exe : fatal error LNK1120: 3 unresolved externals
Our company has a small "Qt Test App" that was written to play around with, which is where I have based my import from. I can compile and link that fine. From what I have gathered, the following properties must be met with Qt files:
Make sure QTDir is included
Add to the UI Files the UIC Compiler
Add to the Resoruce Files the Resource Compiler
Add to the created Header Files the MOC compiler.
I noticed I was missing the MOC Build Tool commands, so I have added them to my UI File's header. However this didnt change the linking problem. I read that I should delete all built files and do a clean to solve it. This didnt work either.
I have checked, and Q_OBJECT is defined in the class.
I am using VS2005 with the Qt Addin. I did not start a new project for Qt however, I am just using the old Visual Studio Solution / VCProj.
Any ideas where to go next?
#Cameron Stubber you need moc object .. You need to modify Custom Build Step.
You can find Custom Build Step in header file (which has Q_OBJECT) Properties by right click. Then type this commands ;
Command Line = $(QTDIR)\bin\moc.exe -I"$(QTDIR)\include\QtCore" -I"$(QTDIR)\include\QtGui" -I"$(QTDIR)\include" -I"$(QTDIR)\mkspecs\$(QMAKESPEC)" finddialog.h -o debug\moc_finddialog.cpp
Description = MOC finddialog.h
Outputs = debug\moc_finddialog.cpp
Additional Dependencies = $(QTDIR)\bin\moc.exe;finddialog.h
But carefull by writing this types you need to change somethings here like $(QTDIR) it is my enviroment variables you need to write full form of where your QT located like D:\qt_5\
and also you need to be carefull finddialog you should write your .h and .cpp files name
And then you need to create a folder by right clicking solution explorer Add\New Filter .. Make folder name as Generated Files
And last step right click Generated Files add\existing item and you will see Debug folder in your solution Project and add moc_"projectName".cpp
Then re-build your solution. Problem will be solved.
Also you should add C/C++ /General/Additional Library Directories
$(QTDIR)\include
$(QTDIR)\include\QtGui
$(QTDIR)\include\QtCore
And Link/General/Additional Library Directories
$(QTDIR)\lib
Link/Input/Additional Dependencies
qtmaind.lib
QtCored4.lib
QtGuid4.lib
But dont forget to change $(QTDIR) to your enviroment variables or location of your qt folder. Like D:\qt_4.7.4
Okay, here's the thing. I have all the IL files I need, namely
DevIL.dll
DevIL.lib
ILU.dll
ILU.lib
ILUT.dll
ILUT.lib
config.h
config.h.in
devil_cpp_wrapper.h
devil_internal_exports.h
il.h
ilu.h
ilu_region.h
ilut.h
ilut_config.h
My project directory looks like this, let's say my project's name is "Project1"
|-Debug---Project1.pdb
|
| |---Debug---[loads of files]
| |
| |---Glut---[OpenGL files]
| |
| |---IL---[all the files mentioned above]
|-Project1---|
| |---image.bmp
Project Folder---| |
| |---[header and .cpp files I made in the project]
| |
| |---[files produced by Visual Studio]
|
|-ipch---[unrelated stuff]
|
|-Project1.sln
|
|-[other files VS created]
I've put all the DevIL files in the IL folder, as mentioned, and I am sure I am using the unicode compatible versions of them, as I am using Unicode Character Set for the project. In my "Additional Dependencies" I have
ilut.lib; ilu.lib; DevIL.lib;
So, the dependencies are there, I know that's not the problem.
After all that, I am still getting linker errors, mainly LNK2019:unresolved external symbol__imp_ for all the IL functions.
What am I missing? It looks to me like maybe something to do with the project properties or the files themselves...maybe I missed a file?
EDIT: Here is the output messages
1>------ Build started: Project: Final Year Project, Configuration: Debug Win32 ------
1>Build started 29/4/2011 12:46:04 pm.
1>InitializeBuildStatus:
1> Touching "Debug\Final Year Project.unsuccessfulbuild".
1>ClCompile:
1> Main.cpp
1>c:\users\xxxx\desktop\final year project 0.2\final year project\main.cpp(152): warning C4390: ';' : empty controlled statement found; is this the intent?
1>c:\users\xxxx\desktop\final year project 0.2\final year project\main.cpp(141): warning C4101: 'alpha' : unreferenced local variable
1>ManifestResourceCompile:
1> All outputs are up-to-date.
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilInit#0 referenced in function "public: static void __cdecl Main::Init(int,char * *)" (?Init#Main##SAXHPAPAD#Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilDeleteImages#8 referenced in function "public: static void __cdecl Main::DisplayScene(void)" (?DisplayScene#Main##SAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilGetData#0 referenced in function "public: static void __cdecl Main::DisplayScene(void)" (?DisplayScene#Main##SAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilConvertImage#8 referenced in function "public: static void __cdecl Main::DisplayScene(void)" (?DisplayScene#Main##SAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilGetInteger#4 referenced in function "public: static void __cdecl Main::DisplayScene(void)" (?DisplayScene#Main##SAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilLoadImage#4 referenced in function "public: static void __cdecl Main::DisplayScene(void)" (?DisplayScene#Main##SAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilBindImage#4 referenced in function "public: static void __cdecl Main::DisplayScene(void)" (?DisplayScene#Main##SAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilGenImages#8 referenced in function "public: static void __cdecl Main::DisplayScene(void)" (?DisplayScene#Main##SAXXZ)
1>C:\Users\xxxx\Desktop\Final Year Project 0.2\Debug\Final Year Project.exe : fatal error LNK1120: 8 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.93
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Since you added the build output, the answer is now easy: your linker errors have nothing to do with DevIL at all.
You need to link to SDL (Simple DirectMedia Layer).
Since SDL has a C interface, and - IIRC - doesn't require that the DLL uses the same heap as the application, the VC8 version of the "Development Libraries" should do fine (even if you use VC10). Just add SDL.lib to the "Additional Dependencies" and you should be fine.
EDIT
OK.
You're either
not linking against the required .lib files (DevIL.lib etc.) or
linking against corrupted/wrong .lib files
At least there is no other explanation I can think of.
The names mentioned in your build log (__imp__ilInit#0 etc.) are correct, and the current "DevIL SDK" (DevIL 1.7.8 SDK for 32-bit Windows) works fine with VC10 (I just verified it).
To assure you're linking against DevIL.lib etc. please put the following in your main.cpp file:
#pragma comment(lib, "DevIL.lib")
#pragma comment(lib, "ILU.lib")
#pragma comment(lib, "ILUT.lib")
To make sure you're linking against the correct version of those files, re-download the whole SDK and try again with the new files.
EDIT 2
Since I got half the reward, I feel I should be more helpful :)
One last thing you can try: enable verbose linker output to check if the linker finds the correct version of DevIL.lib. (If it didn't find any DevIL.lib, you would get an error LNK1104: cannot open file 'DevIL.lib' - and since you're not getting that message, that cannot be the problem.)
To enable verbose linker output, add the /VERBOSE switch (under Configuration Settings -> Linker -> Command Line -> Additional Options).
That will give you a ton of messages. Copy them into your favorite editor, and search for lines containing DevIL.lib. One of the lines should read Searching X:\path\to\DevIL.lib: - that's the path to the copy of DevIL.lib the linker is using. If that's not the path where you copied the files from the SDK you downloaded, you have found the problem.
And if there are no lines containing DevIL.lib, then the linker isn't even trying to locate it. However I've never seen #pragma comment fail, so if you indeed added those lines that almost surely cannot be the case.
BTW: please let me know if you managed to solve this. This is so strange that I really want to know what was going on :)
You need to tell the linker to link against the IL libs.
Project settings, Linker, Input
Make sure the directory the libs are in is in the Additional directorys field too.
I've noticed your config.h.in file should have .win extension because that it is in DevIL-SDK-x86-1.7.8.zip package. And there's no devil_cpp_wrapper.h file also.
Finally i solved this in this way:
Header files
config.h
config.h.win
devil_internal_exports.h
il.h
il_wrap.h
ilu.h
ilu_region.h
ilut.h
ilut_config.h
goes to VC include directory - all in one directory named IL (c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\IL\ by default)
Liblary files
DevIL.lib
ILU.lib
ILUT.lib
goes to lib directory (c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\ by default)
DLL files
DevIL.dll
ILU.dll
ILUT.dll
goes to project dorectory (...\Project Folder\Project1\ in your case)
Then i added liblary files to project by right click on project->Properties->Linker->Input->Additional Dependencies (wrote just name of liblaries like ILU.lib)
In my project I just include IL\il.h, IL\ilu.h and IL\ilut.h
I think you may got wrong files by the way...
Just in case you never got this worked out, or anyone else has the same problem (like I did):
I had downloaded the 64-bit version of DevIL for my 64-bit Windows computer, but Microsoft Visual Studio (I was using Express) was the 32-bit version.
I downloaded the 32-bit version of DevIL and it worked!
I had the same problem. Seems like the pre-built binaries are swapped: I could link to the ones designated as non-unicode but they would utterly fail trying to use my non-unicode strings and return unicode strings. Try to build your own binaries from the source or use a previous version.
you should compare the function signatures that you see in your errors with the signatures you get with depends.exe (depedency walker). If they differ there may be a compiler-issue.
You may then try to compile with :
extern "C" {
// put your devils-include directives here ...
}
Nothing garantied of course , just a suggestion.
You may also check the 'Additional Library Directories' property on your 'Linker\General' page to see if (when used) it points to the right directory for your build (if you also added a path to the standard VC lib-directories their may be a conflict ,use either one but not both).
Another suggestion is to create a new project and do it all over again ,you may have made an ever so little mistake.
Good luck !
I had the same problem.
In my case it was problem with code in all devil`s .h files
#ifdef _WIN32
#if (defined(IL_USE_PRAGMA_LIBS)) && (!defined(_IL_BUILD_LIBRARY))
#if defined(_MSC_VER) || defined(__BORLANDC__)
#pragma comment(lib, "%LIBNAME%.lib")
#endif
#endif
#endif
after second #if code was deactivated.
i added #pragma comment(lib, "DevIL.lib") (and 2 more) into my main.h and linker errors dissapeared.
sorry for my bad english =[
I don't know if this question is still active, but since it has no chosen answer, I'll post this. I had what seems like the exact same problem with DevIL version 1.7.8. To fix it, I rolled back the version to 1.7.7 and used #undef _UNICODE before including the headers and #define _UNICODE afterwards. The project compiled without linker errors and worked without a hitch. On 1.7.8, the libraries seem to all be unicode, or at least they don't seem to support ascii very well. However, this may just be some weird compatibility issue with my computer as it does not seem to be a common problem
It might be that you have to declare some preprocessor variable to actually tell the compiler that you are importing symbol; I mean something related to __declspec( dllimport )
I did exactly as what Sarah said about the 32-bit or 64-bit Visual Studio versions. I'm on a 64-bit computer running a 32-bit Visual Studio 2012. I obtained this error when I used the x64 DevIL files. Getting the x86 version helped. Here's the basic steps I took to ensure it does run:
Right-click your project and go to Properties.
Under C/C++ > General, add DevIL's 'include' folder under Additional Include Directories.
Then under Linker > General, add DevIL's 'lib' folder (it should contain: DevIL.lib, ILU.lib and ILUT.lib) to Additional Library Directories. For x64 it may not contain a lib folder, it may be just the DevIL directory itself (for version 1.7.8 it was that case).
Also in Linker > Input, add those .lib file names into Additional Dependencies.
Now that should be all you need to do in the project properties. In the main.cpp you should include the appropriate header files and it should work when you initialize.
Example:
#include "IL/il.h"
#include "IL/ilu.h"
#include "IL/ilut.h"
int main(){
ilInit();
iluInit();
ilutRenderer(ILUT_OPENGL); //these are just to initialize
}