I am working on porting an app of mine that I made in OS X to Windows 10. I'm using visual studio 2015 Community Edition.
To get the project running, I need to link against GLFW and, in Windows as I understand, GLEW, since I am targeting GL 4.5.
So I have the glfw and glew libs. I also use Cygwin so I have the libs installed in usr/local/(bin | lib | include) to mimic the folder structure I'd use in OS X for these libs.
The issue I'm having is with the opengl lib itself.
Until yesterday, I had managed to get my project compiling and initializing the glfw window with the following visual studio settings:
Project->Properties-> :
C++->General:
Additional Include Directories:
C:\cygwin64\usr\local\include
Linker->General:
Additional Library Directories:
C:\cygwin64\usr\local\lib
C:\cygwin64\usr\local\bin
Linker->Input:
opengl32.dll
glew32s.lib
glfw3.lib
The first thing to notice is that I was linking against opengl32.dll, not .lib. I saw a bunch of questions / posts online that state that when you install Windows SDK you have a opengl32.lib in Program Files/Microsoft SDKs/Windows (x86 or otherwise). This is not the case for me. I have even reinstalled the Windows 10 SDK and it does not install any opengl lib, static nor dynamic, anywhere.
So I'm pretty sure that my opengl dll was coming from Windows/System32 because that is the only place in the whole machine where there is any sort of opengl lib.
Which makes me think I might have also had C:\Windows\System32 in the linker's additional library directories section. I say makes me think, because I had set this up with a lot of struggle about a week ago. Since then I was able to develop just fine.
Last night all I did was commit my work to a git branch, switch to another branch and merge to that branch. After the merge, all Visual Studio linker/C++ settings were wiped. So I had to recreate them, as I showed above.
Now what happens is that if I include C:\Windows\System32 and the opengl32.dll VS spits out:
LNK1107 invalid or corrupt file: cannot read at 0x2E0 OpenVRTest C:\Windows\System32\opengl32.dll
And if I don't include it obviously half the stuff in glfw is unresolved.
Any hints as to how to get this working again?
It makes no sense to me... It was working just fine and it has to have been working fine with this opengl32.dll
Also as a side note, I'm not sure why people insist that installing the Windows SDK installs a static version of the gl lib; at least it does not for me.
Linker->Input:
opengl32.dll
glew32s.lib
glfw3.lib
That opengl32.dll is wrong. In Windows development the linker always takes .lib files. In case of static libraries the .lib contains the actual library binary. In case of DLLs the corresponding .lib informs the linker about which DLL to use and which symbols it offers.
The main reason for this particular choice of how things are to be done was, that in Windows development it shall be possible to link against a DLL without having the actual DLL around.
Also system libraries always are suffixed …32 even on 64 bit systems.
The issue was that among the VS configuration settings that got wiped, were a couple things related to x86 vs x64 platform settings. So the project was now trying to build for 64bit linking against the 32bit dll in System32.
So that's that.
A separate issue is why a lot of answers speak of an opengl32.lib (static) that theoretically comes with the Windows SDK but I have not seen it anywhere. I just link against the dynamic one.
Related
I've written a game using OpenGL, GLFW, C/C++. I use third party libraries like SOIL and irrKlang. I use Microsoft Visual 2015. Both the debug and release version run ok from visual studio. In properties -> C++ -> Code Generation-> Runtime Library I selected /MDd. I did try other settings but the release version wouldn't work with any other. All of my .dll are saved in the release and debug folders.
However, when I go to my release folder and copy and paste the .exe found there, onto my desktop,it no longer runs. I keep getting a message that says the irrKlang.dll is missing. Could someone please explain how to get a standalone .exe of my game up and running?
Two things here. First, the .exe is the executable which contains the entry point of your application. So this is indeed the first piece you need. However, your application is allowed to depend on code that's not linked into it statically, but rather dynamically -- such dynamically linked code is only loaded at runtime. These runtime libraries of code are called DLLs ("dynamically linked libraries").
If your application depends on a DLL, it will look for that DLL while it's running. If it doesn't find it, you'll see that message box about a missing DLL. So, you need to copy not only the .exe file, but all the .dlls it depends on (and that they depend on) too. Note that your application links against many default system DLLs, e.g. kernel32, but these don't need to be copied next to the .exe because they're always present in the system search path.
Now, the second part. If you want to run your application on a PC that doesn't have Visual Studio installed, you need to make sure that computer has the C/C++ runtimes that the VS2015 toolchain automatically links against installed. These are not DLLs that you copy by hand; rather, there is a redistributable installer for them which installs them globally on the PC for all applications. You can ship this with your own installer.
For this to work, you want to be linking with just /MD in Release (the debug CRT is for debugging only, and is only installed when Visual Studio is installed -- it's not meant to run outside your PC).
This statement:
"Both the debug and release version run ok from visual studio. In properties -> C++ -> Code Generation-> Runtime Library I selected /MDd. I did try other settings but the release version wouldn't work with any other."
Leads me to believe that maybe you don't have a release version of one of your third party libraries.
/MDd causes your application to use the debug version of the MS runtime, which means that something in your project is being built with or as a debug version.
I use the 'depends.exe' application to see the dependencies of my executables and DLLs. It used to be provided directly by Microsoft, but now seems to be supported via a third party. Older SDKs will have it.
http://www.dependencywalker.com/
To give you an idea of what I am really trying to do. My goal is to create a c++ program in Visual Studio and using OpenGl display a blackscreen and a white dot in the middle of the screen.
Before I can even get to the coding part though, I have to include the OpenGL library somehow.
Looking at OpenGL documentation they say that it's already installed, I just need to initialize it.
I'd rather not have to do all the initialization work as it's already been done several times, such as FreeGLUT, but I have 2 real problems that I currently just do not understand.
1) How do I compile FreeGlut?
I've downloaded the source code for FreeGLUT here http://prdownloads.sourceforge.net/freeglut/freeglut-3.0.0.tar.gz?download
I configured it with CMAKE into a visual studio 2013 compatible project.
but once I open it with Visual Studio and try to compile it, I get a bunch of errors saying:
Error C1083: Cannot open include file: 'EGL/egl.h': No such file or directory c:\freeglut-3.0.0\include\gl\freeglut_std.h 136 1 One_static
2) Once I get it compiled, how do I link it to my c++ project so that I can do
#include<FreeGLUT.h>
or
#include <GL/glut.h>
?
Most likely CMake did configure it wrong; EGL is used in embedded systems (think Android, set-top boxes, and such) not Windows. Double check that CMake does something sensible there.
After you've built FreeGLUT copy it somewhere convenient (do not copy it into the Visual Studio installation directory) and add the directories where you placed FreeGLUT to your own OpenGL project's compiler and linker search paths (reachable in the Visual Studio Build configuration).
Personally I place customly built libraries at
C:\local\include\ (the header files)
and
C:\local\lib (the .lib, .a and .dll files)
I also tend to give libraries an architecture infix like x86_32 or x86_64. e.g. freeglut-x86_64.dll. It's unlikely Windows will ever get some kind of "fat binary" in which the code for several architectures can be merged.
For convenience put the DLL path into the system search path for DLLs. When deploying your program copy the required DLLs into the same directory as the EXE files.
I am new with visual studio, opencv.
I am using visual studio 2013, opencv and c++ for my project.
I configured (copied path) the opencv and other library to my computer environment system.
After run the project in visual studio, normally, there will be an exe file in the project.
I can copy the exe file in the project folder and copy to other place in my computer and it will run normally.
This is because my computer environment systems are configured with opencv and other library.
I want to do the same thing with other computers BUT I do not want to manually configure each computer with opencv and other libraries.
Are there any ways that I can do to link everythings all in exe file after run the project in visual studio 2013 so that I can run the exe without depend on the path of libaries and opencv?
EDITED
I use opencv installer opencv2.4.7.exe
In the current VS2013 my project, i configured my project and opencv installer as this link
http://www.anlak.com/using-opencv-2-4-x-with-visual-studio-2010-tutorial/
question : Can i use the library in folder C:\opencv\build\x64\vc11\staticlib come from the opencv installer no need create my own library from source opencv?
question : In case i need to generate new library from opencv source (http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html) or use lib in static folder of opencv installer, if i want to include it all to exe files, do i need to create new project and reconfigure?
Thank you.
First you need to rebuild openCV to generate static libraries instead of dynamically linked ones. This way all code that your application uses is thrown together in one single exe-file (which will probably be significantly bigger). This exe-file you can move to other computers and they should still work there, provided they have an architecture that is at least compatible with yours. So if you build it on an x86 perconal computer (32-bit), it should basically work on any other personal computer. If you build it on a x64 computer (AMD 64-bit), it will only run on other x64 machines. At least this is true assuming both systems use the same syscall API (Windows NT, POSIX...).
For openCV you do this by setting the BUILD_SHARED_LIBS build flag to false (see OpenCV as a static library (cmake options), the following line is taken from there):
cmake -DBUILD_SHARED_LIBS=OFF ..
Once you have done this, you will see that the openCV folder looks very similar to the one you have now, except that in your 'lib' folder there will now be .lib-files instead of .dll files (at least if you are working on Windows, which I assume you do since you are using Visual Studio).
Next step is to go to your project settings and set your linker to link with the static libraries instead of the dynamically ones. If you have used openCV's local method for linking, you can go to project settings -> linker -> input -> Addtional dependencies. There you change the extension of all the openCV libraries from .dll to .lib.
Now you should be able to rebuild your application and the resulting exe-file should have all dependent libraries contained in it.
When i use Visual Studio, my executables depends on microsoft redistributable package - the package that deploys MS's runtime DLLs. That is annoying to me. What disatwantages my executable would have if i would use MinGW?
I also want to try link with lib- avcodec/avformat, that are built by MinGW and i have no my own mind power to build them in VS from src.
In case of using MinGW you will depend on DLLs that are shipped with mingw. It is not big deal to change one vendor to another.
If you already have MS project, review possibility to statically link MS libraries (it is option is provided for some of VisualStudio projects on creation time in project options)
You can link everything statically with MinGW. Use the -static linker flag.
No need for redistributing any DLL's, but you have to make sure that in the c++, there's no exceptions being passed over DLL boundaries (so make sure every C++ library is linked statically in this case).
I've made an application using both the OpenCV and WxWidgets library. The code runs fine on my development machine.
However, when I transfer it to another windows machine I get the error
*"The program can't start because cv110.dll is missing from your computer.
Try reinstalling the program to fix this problem".*
Now, I'm guessing installing the same versions of OpenCV and WxWidgets as used in development would resolve this problem but this is a bit much to ask of a casual 3rd party user of my code.
In my IDE (Windows Visual C++ 2008) I've linked to the relevant .lib files by going to Properties->Linker->Input
How would I go about packaging the .exe so that it works on non-development machines?
i.e. if I include the .dll files, how would I need to change the linker configuration to reflect this ? Or, can the .dll files referenced by the .lib files be incorporated into the .exe ?
Sorry, I know this issue has come up before but I can't seem to find a resolution specific to my case. Any help would be appreciated!
OpenCV is built using dynamic libraries
The correct thing to do is create an installer containing your exe and the correct dlls you need. See https://stackoverflow.com/questions/1285591/installer-recommendation