glload and LNK errors in VC++ EE 2010 - visual-studio-2010

I'm trying to use glload from the Unofficial OpenGL SDK but I get LNK errors:
1> LINK : C:\Users\T\documents\visual studio 2010\Projects\testi\Debug\testi.exe not found or not built by the last incremental link; performing full link
1>glloadD.lib(gll_gl_ext.obj) : error LNK2019: unresolved external symbol __imp__wglGetProcAddress#4 referenced in function _WinGetProcAddress
1>glloadD.lib(wgll_ext.obj) : error LNK2001: unresolved external symbol __imp__wglGetProcAddress#4
1>C:\Users\T\documents\visual studio 2010\Projects\testi\Debug\testi.exe : fatal error LNK1120: 1 unresolved externals
#include <glload/gl_all.h>
#include <glload/gll.hpp>
void main()
{
glload::LoadFunctions();
}
Linker/Additional Dependencies: glloadD.lib
Where is the problem ?
Edit 1:
First I used Premake to generate build files for vs2010. Then I built all libraries. In my project I set Additional Include Directories, Additional Library Directories and Additional Dependencies for those libraries. I want to run an example from this page: link but I forgot to create OpenGL context before loading opengl functions. I don't need a window in this project so I just call glutInit, but I get an unhandled exception at 0x5bfed398 (msvcr100d.dll)
#include <glload/gl_all.h>
#include <glload/gll.hpp>
#include <freeglut/freeglut.h>
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glload::LoadFunctions();
}
Edit 2:
Calling glutCreateWindow before glload::LoadFunctions seems to be necessary. Following code works:
#include <glload/gl_all.h>
#include <glload/gll.hpp>
#include <freeglut/freeglut.h>
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutCreateWindow("");
glload::LoadFunctions();
}

The solution is to create a working context before initializing GlLoad. I've had this problem every time i've started an OpenGL project with GLSDK.

Related

How to dll import and export HINSTANCE from a .dll in c++?

I am trying to get the HINSTANCE of a .dll, but I get this error:
error LNK2019: unresolved external symbol "__declspec(dllimport) struct HINSTANCE__ * m_instance" (__imp_?m_instance##3PEAUHINSTANCE__##EA) referenced in function...
This is the code of the .dll:
#include <Windows.h>
__declspec(dllexport) HINSTANCE m_instance;
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID)
{
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
m_instance = (HINSTANCE)hModule;
}
return TRUE;
}
This is the code of the application:
__declspec(dllimport) HINSTANCE m_instance;
// use it for whatev
In summary, I need a way to get the HINSTANCE from my .dll into my .exe.
In summary, I need a way to get the HINSTANCE from my .dll into my .exe.
But, why??? Once the .exe has loaded the .dll into its memory, the .exe already has access to the .dll's HINSTANCE, from the return value of either LoadLibrary/Ex() or GetModuleHandle(). So, there is never a need to have a .dll export its own HINSTANCE.
The application is failing to link against the DLL's import library. By default, MSVC's linker generates an import library (LIB) when producing a DLL, that has the same base name as the DLL.
To allow the linker to resolve the symbol m_instance the application needs the DLL's import library as a linker input file. See .Lib Files as Linker Input to learn how to add linker input files in Visual Studio.
Though not strictly required, it's usually a good idea to export symbols using C linkage. While C++ linkage is largely unspecified and very toolchain-specific, C name decoration is de-facto standardized. The changes required are tiny (though, again, not required):
extern "C" __declspec(dllexport) HINSTANCE m_instance;
and
extern "C" __declspec(dllimport) HINSTANCE m_instance;

debug assertion failure during domodal

I have just started working on CDialog classes. When I try to execute the following code, I am getting debug assertion failure.
#include "stdafx.h"
#include "resource.h"
#include <afxwin.h>
#include "dialog.h"
#include <Windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
dialog dial(NULL);
dial.DoModal();
return 0;
}
I have created a dialog resource and CDialogEx class named dialog. The error I am getting is
"Debug Assertion Failed!
Program: ...pp_projects\ConsoleApplication1\Debug\ConsoleApplication1.exe
File: f:\dd\vctools\vc7libs\ship\atlmfc\include\afxwin1.inl
Line: 24"
Can anyone give me a solution?
Your project name suggests that you have created a Win32 Console Application project and added the MFC stuff. What you need to create is a MFC Application project.
MFC can also be used in a console application, but then you would not show dialogs and you would need to initialize MFC first.

VC++ Multiple Project Solution

I am very new to C++ and I am attempting to setup multiple projects in the same solution in VS2013. Currently I have stepped back to a simpler example project to try to figure out my error.
Project 1:
Main.cpp
#include "Test.h"
#include <iostream>
using namespace std;
int main()
{
cout << _MOVEMENTSPEED();
system("pause");
return 0;
}
Project 2
Test.h
#ifndef TEST_H
#define TEST_H
int _MOVEMENTSPEED();
#endif
Test.cpp
#include "Test.h"
int _MOVEMENTSPEED()
{
return 10;
}
Whenever I attempt to build this I get the error "error LNK2019: unresolved external symbol "int __cdecl _MOVEMENTSPEED(void)" (?_MOVEMENTSPEED##YAHXZ) referenced in function _main c:\Users\Max\documents\visual studio 2013\Projects\Project1\Project2\Main.obj" and "Error 2 error LNK1120: 1 unresolved externals c:\users\max\documents\visual studio 2013\Projects\Project1\Debug\Internal".
UPDATE
I tested this same code but within one project file in visual studio and it worked fine.
When you create multiple projects you should do the following:
Make sure the following:
Include the .h file properly from other project(Generally every project has its own directory), so you need to include the file like below:
#include "..\Test\Test.h"
Export the function / class by using _declspec(dllexport) and _declspec(dllimport)
Include the .lib file properly in the project settings of Link tab.
Set the project dependencies correctly.
The below links should help you:
http://support.microsoft.com/kb/815650
http://msdn.microsoft.com/en-us/library/799kze2z.aspx

Opencv in visual studio 2010 [duplicate]

I'm trying to use opencv 2.3 with Visual Studio 2010 Express. My code is from example:
#include "stdafx.h"
#include <highgui.h>
int _tmain(int argc, _TCHAR* argv[])
{
int c;
// allocate memory for an image
IplImage *img;
// capture from video device #1
CvCapture* capture = cvCaptureFromCAM(1);
// create a window to display the images
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
// position the window
cvMoveWindow("mainWin", 5, 5);
while(1)
{
// retrieve the captured frame
img=cvQueryFrame(capture);
// show the image in the window
cvShowImage("mainWin", img );
// wait 10 ms for a key to be pressed
c=cvWaitKey(10);
// escape key terminates program
if(c == 27)
break;
}
return 0;
}
What have I done so far?
Added build\bin and one of build\{x86|x64}\{vc9\vc10\mingw}\bin to my system path (to use DLLs).
Added build\{x86|x64}\{vc9\vc10\mingw}\lib or build\{x86|x64}\{vc9\vc10\mingw}\staticlib as library directories to my linker settings.
Added build\include and build\include\opencv as include directories to my compiler settings.
And the result is:
1>LINK : fatal error LNK1104: cannot open file 'c:\OpenCV2.3\build\x86\vc10\lib.obj'
There's no lib.obj in OpenCV folders. I've only unziped OpenCV-2.3.0-win-superpack.exe, without using CMake software.
What am I doing wrong?
Well, the official guide is for installing OpenCV 2.1 on VS2010, so I wrote some instructions below that shows how to properly install and configure the x86 version of OpenCV 2.3 on Visual Studio 2010 (Express), since a lot of folks seem to have problems setting it up correctly.
Download OpenCV-2.3.0-win-superpack.exe and execute it to extract all files to a folder named OpenCV2.3. Inside this folder there are 2 directories: build and opencv. All the setup on VS2010 will refer to the build directory. For practical purposes I moved the folder OpenCV2.3 to my C:\ drive, so pay attention to the paths I suggest on this guide as yours might be different.
On Visual Studio, create a new Win32 Console Application project and name it whatever you like. After that, a new window will show up. Click on the tab Application Settings and make sure the option Empty Project gets selected:
Add a new file main.cpp to the folder Source Files, then add this code to main.cpp:
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char* argv[])
{
if (argc < 2)
{
printf("Usage: ./opencv_hello <file.png>\n");
return -1;
}
IplImage* img = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);
if (!img)
{
return -1;
}
cvNamedWindow("display", CV_WINDOW_AUTOSIZE);
cvShowImage("display", img );
cvWaitKey(0);
return 0;
}
At this point, we need to configure the project so it can locate OpenCV headers and libraries. Go to the Project Properties (ALT+F7), and once the new window shows up do the following:
On the Configuration box, select All Configurations
Open Configuration Properties > C/C++ > General, and edit the field Additional Include Directories to add these 3 paths (for the headers):
C:\OpenCV2.3\build\include\opencv
C:\OpenCV2.3\build\include\opencv2
C:\OpenCV2.3\build\include
Note that include\opencv is for the C interface of OpenCV and include\opencv2 if for the C++ interface. We are also adding the folder include to prevent our build from being broken by some headers of the C interface that refer to C++ headers as opencv2\core.
Then, add the path of the libraries on Configuration Properties > Linker > General, and on the Additional Library Directories field, add this: C:\OpenCV2.3\build\x86\vc9\lib:
Finally, for this simple test we are going to add the libraries opencv_core230.lib and opencv_highgui230.lib. So go to Configuration Properties > Linker > Input and add them:
When writing more complex applications you'll probably need to add other OpenCV libs that I did not
mentioned on this little project of ours.
Press F7 to Build Solution and you should see:
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
To be able to execute the application you'll need to modify the PATH environment variable of your system to add the location of OpenCV's DLLs. Add this to end of PATH:
; C:\OpenCV2.3\build\x86\vc9\bin
If you are struggling with editing the PATH environment variables, you can also copy the required .dll files to your project folder:
The dll files are located in this folder ../OpenCV2.3/build.x86/vc9/bin
Then copy them to the folder where .exe file is created:
c:\Users\PIMMES\Documents\Visual Studio 2010\Projects\eigenfaces\Debug (Ofcourse you have to change the path to your Debug folder)
You only have to copy the .dll files which you are using in your project (#include for example) For example if you get an error message saying opencv_core231d.dll is not found then get this .dll file from the above location (bin folder) and copy to your project Debug folder.
Hope this helps..
Whenever I make a program that uses opencv 2.2 or greater I include everything, and then comment out the libraries I don't need. Try this, I'm sure you need more than highgui.h
#include "opencv2\opencv.hpp"
using namespace cv;
//#pragma comment(lib, "opencv/opencv_calib3d231.lib")
//#pragma comment(lib, "opencv/opencv_contrib231.lib")
#pragma comment(lib, "opencv/opencv_core231.lib")
//#pragma comment(lib, "opencv/opencv_features2d231.lib")
//#pragma comment(lib, "opencv/opencv_flann231.lib")
//#pragma comment(lib, "opencv/opencv_gpu231.lib")
//#pragma comment(lib, "opencv/opencv_haartraining_engine.lib")
#pragma comment(lib, "opencv/opencv_highgui231.lib")
//#pragma comment(lib, "opencv/opencv_imgproc231.lib")
//#pragma comment(lib, "opencv/opencv_legacy231.lib")
//#pragma comment(lib, "opencv/opencv_ml231.lib")
#pragma comment(lib, "opencv/opencv_objdetect231.lib")
//#pragma comment(lib, "opencv/opencv_ts231.lib")
//#pragma comment(lib, "opencv/opencv_video231.lib")

Unable to link in C++/CLI application

I am trying to wrap a C++ class "OpenViBE::Kernel::CPlayer" into a Managed C++ application, so I can later use it in C#.
#include "stdafx.h"
#include "ovkCPlayer.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
const OpenViBE::Kernel::IKernelContext* r=nullptr;
OpenViBE::Kernel::CPlayer* c=new OpenViBE::Kernel::CPlayer(*r);
//c->initialize();
return 0;
}
The above code compiles, it but does not link. The "OpenViBE::Kernel::CPlayer" is in project "OpenViBE-kernel-dynamic". I found where is the lib file from Properties->Linker->Advanced->Import Library. Then I added this folder to the lib path of my project (above) and the "OpenViBE-kernel-dynamic.lib" to the Linker->Input->Additional dependencies.
So the lib file is there, but the linker still can not link it:
error LNK2019: unresolved external symbol "public: __thiscall OpenViBE::Kernel::CPlayer::CPlayer(class OpenViBE::Kernel::IKernelContext const &)" (??0CPlayer#Kernel#OpenViBE##$$FQAE#ABVIKernelContext#12##Z) referenced in function ...
I do not have experience in writing C++/CLI applications, so I think I am missing something.

Resources