How to link Lua in Microsoft Visual C++.2010 Express? - c++

I am trying to write C++ classes/functions which can be accessed from Lua.
I need to export the C++ library as dll files.
I'm using Microsoft Visual C++.2010 Express
So I create a project and add the require .cpp files and .h files
Now when I try to build, the following error occurs.
mylib.obj : error LNK2019: unresolved external symbol _lua_settop
referenced in function "void __cdecl g_initializePlugin(struct
lua_State *)" (?g_initializePlugin##YAXPAUlua_State###Z)
Similar errors occur for all lua functions. When Googling I learnt that I had to link LUA.
How can that be done in Visual C++.
P.S
I found a solution which directed me to give
#pragma comment( lib, "lua5.1" )
For this solution, it requires a lua5.1 file. From where should I download that file and where should it go (in the project folder?) ?

OK! I figured out how!
To link Lua, the following has to be done after the C++ project has been created.
Copy C:\Program Files\Lua\5.1\lib\lua5.1.dll to your project folder
Copy C:\Program Files\Lua\5.1\lib\lua5.1.lib to your project folder
Right Click on Project --> Properties --> Configuration Properties
--> Linker --> Input.
Add lua5.1.lib to Additional Dependencies
Right Click on Project --> Properties --> Configuration Properties
--> VC++ Directories.
Add C:\Program Files\Lua\5.1\include to Include Directories
NOTE : my lua installation is in C:\Program Files\Lua\5.1
Now on building the project, dll file is created!

Related

Unable to use gmsh from Visual Studio C++

I downloaded the sdk and ran the Windows related commands described here.
Then I created a new VC++ project and copied the contents of a tutorial file included with that sdk (t1.cpp).
There were compile time errors, which I fixed by including the path to gmsh.h in the include settings found in projcet->Properties->Configuration Properties->C/C++->General->Additional Include Directories.
I also included path to the gmsh.lib file at projcet->Properties->Configuration Properties->Linker->General->Additional Libraries Directories.
Still I am getting the below error while trying to build the project:
LNK2019: unresolved external symbol gmshFree referenced in function "int __cdecl gmsh::model::geo::addCurveLoop(class std::vector<int,class std::allocator<int> > const &,int,bool)" (?addCurveLoop#geo#model#gmsh##YAHAEBV?$vector#HV?$allocator#H#std###std##H_N#Z)
Please say what I am missing here. I am running Microsoft Visual Studio Community 2019 (Version 16.10.4) on Windows 10.
Did you add #include "gmsh.h " and add gmsh.lib in Configuration Properties > Linker > Input? For more information, you could refer to the document: Create a client app that uses the DLL.

Error Building Dlib Visual Studio 2015

I have been trying to compile dlib library in visual studio.
So I created an empty project.
I added face_landmark_detection_ex.cpp and source.cpp from dlib/all folder into my project (I copied paste the aforementioned into "Source Files" in my project).
I added: C:\Users\user\Desktop\dlib2\dlib-19.4 and C:\Users\user\Desktop\dlib2\dlib-19.4\dlib\external\libjpeg and C:\Users\user\Desktop\dlib2\dlib-19.4\dlib\external\libpng into the include directory.
And added DLIB_PNG_SUPPORT and DLIB_JPEG_SUPPORT into the C/C++ -> Preprocessor -> Preprocessor Defintion.
the platform chosen is Active(win32).
Under Debugging -> Command Argument, I added the following arguments: C:\Users\user\Desktop\dlib2\dlib-19.4\shape_predictor_68_face_landmarks.dat C:\Users\user\Desktop\dlib2\dlib-19.4\examples\faces*.jpg
When trying to build the project I got the following errors:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _png_set_sig_bytes referenced in function "private: void __thiscall dlib::png_loader::read_image(char const *)" (?read_image#png_loader#dlib##AAEXPBD#Z) dlibTest c:\Users\user\documents\visual studio 2015\Projects\dlibTest\dlibTest\source.obj 1
Any help is much appreciated!!
You have to add the source files from the libpng and libjpeg folders too.

OpenGL in Visual studio - Issues with GLEW

I'm currently following the openglbook.com tutorials (set up) (Tutorial) and have run into an issue fairly early on. I'm getting the following two errors:
1>main.obj : error LNK2019: unresolved external symbol __imp__glewGetErrorString#4 referenced in function _Initialize
1>main.obj : error LNK2019: unresolved external symbol __imp__glewInit#0 referenced in function _Initialize
I have downloaded and compiled freeglut 2.8.0 as well as the glew 1.9.0 binaries. I have copied the libs and includes to C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Lib and Include respectively.
The Lib and Include paths have also been added to my project properties under Additional Library/Include directories.
I have also defined glew32.lib and freeglut.lib in my linker->Input->Additional dependencies.
I have included GL/glew.h and GL/freeglut.h at the top of my main file.
What am I missing? Every other thread I've found has been solved by adding the directories to the project properties. Does anyone have any ideas?
This means that you try to use GLEW as a DLL (because your application looks for a name that begins with __imp, like "import" ), but you didn't built GLEW as a DLL (because otherwise it would work).
3 possible options :
Rebuild GLEW with the GLEW_BUILD preprocessor definition (Project->Properties->C++->Preprocessor->Additional definitions). Then rebuild your application.
Don't build GLEW at all. Simply put glew.c in your application's project. This is the easiest way.
(my favourite) Define GLEW_STATIC in your application's preprocessor definitions, and rebuild.

How do I build and link libCurl in VS project

I am trying to use cURL in a C++ project I am working on in VS2010.
I downloaded the latest cURL source and I am building the solution included in the archive. When I build this project the only output lib appears to be "libcurld_imp.lib". I was expecting a "libcul.lib". In any case I have pointed VS to the include directory where the headers live and added the above mentioned lib to my linker's dependencies. Finally, I add the folder path of this "libcurld_imp.lib" to the links additional libraries search locations.
I cannot build my project because of the following linker error:
error LNK1104: cannot open file 'libcurld_imp.lib'
This file does exist in a folder that I added to the linker's additional libraries search path. What am I missing? Thanks
update
Ok.. So was able to get a libcurl.lib file by editing the libcurl proj. The default build settings were set to output a DLL. I changed this to as static library. Now that I have a libcurl.lib I am getting these linking errors:
Error 3 error LNK2019: unresolved external symbol _imp_curl_easy_setopt referenced in function _main
Error 2 error LNK2019: unresolved external symbol _imp_curl_easy_perform referenced in function _main
Anyone know how to link this friggen thing?
Another update
The documentation included in the source download includes a file, "build.windows". The directions say to build the lib using the following command:
nmake /f makefile.vc mode=
I have done this using "static" as my mode and "VC=10" as my option. This builds the library but it is called libcurl_a.lib. Linking to this lib gives the same errors :(
Thanks
the _imp suffix in libcurld_imp.lib most likely stands for Import Library. You are building a DLL and this file is the lib you need to link to your exe to call the DLL implicitely.
The solution should contain other configurations that will let you build a static library.
You need both to succeed. Try this suggestion (it's for vs2008 but should work):
http://curl.haxx.se/mail/lib-2009-05/0097.html

DevIL library files and dependencies

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
}