I am studing OpenGL and I usually study in the laboratory in my university.
My problem is that the computers in the university don't have the necessary libraries installed for me to study the programs, and I have only user permissions in these computers, so I can't install anything that need administrator permissions.
Usually I develop in a linux environment, but the computers on the lab all got Windows XP or Windows 7 running. I use g++ to compile my programs, freeglut and opengl library. I also use the OpenGL extensions to be able to use vertex array objects for example, and other features to the newers versions of OpenGL.
I am thinking if that is a way to put everything I need in my pendrive and just execute this in every computer I go, without having to install nothing. Maybe something like put all the libraries with cygwin and a notepad++ portable in the pendrive and compile my programs using the cygwin on the pendrive.
But how can I achieve this, what modifications I need to do on my code?
Edit:
To solve my problem I did the following:
Installed MinGW with MSYS in my PC;
Create a batch file (.bat) named startMinGW with the following code inside MinGW folder:
#echo off
mode con:cols=130 lines=50
path=%path%;%CD%\bin
path=%path%;%CD%\lib
path=%path%;%CD%\msys\1.0\bin
title MinGW Compiler
echo Ready!
cmd.exe /K
Execute the batch file to compile the following;
Compile freeglut 2.8.0 with MinGW, going in the root folder of freeglut and executing:
sh configure
make
Compile glew 1.9.0 with MinGW, going in the root folder of freeglut and executing:
make
Copied the .h files localized in the include folders of freeglut and glew, to the include folder of MinGW
Copied the .a, .dll, .la, .lai (I don't know if it's necessary to copy the .la and .lai files) files localized in the lib folders of freeglut and glew, to the lib folder of MinGW
Copied the folder C:\MinGW to my pendrive.
Now to compile an OpenGL program I just need to execute startMinGW from the pendrive and execute
g++ file.cpp -lopeng32 -lglu32 -lglut -lglew
The glut (or freeglut) lib is cross-platform. Why wouldn't you compile it on Windows ?
Use a build generator (like CMake) to easily create your makefile on each platform and you're done.
Qt OpenGL API is probably the best fit in your case.
Related
I haven't programmed for a while and am trying to set up my build environment on a new laptop. I've just forgotten how and think that I did allot of things wrong last time!
What I'm trying to do is have that common Include Directory and common Lib directory so when I build projects or other dependencies, etc... my compiler is able to find all the include and lib files it needs. I'm not formally trained so some obvious things to you guys are learning points for me.
I'm going to use a Mingw compiler and MSYS. Off memory I put the Include directory and the lib directory in the Mingw directory but I could be wrong there.
I'm just trying to set up an effective and simple build environment on Windows 7.
Where should all my directories go? Thanks
If you aren't already, MSYS2 is generally preferred over MSYS. I'm going to answer this assuming MSYS2. I use the 64 bit version, so that is what I'll show, but it should be simple enough to change.
I will also assume you put the msys64 directory in the base directory, if not replace C:/msys64/ with C:/wherever/you/put/it/msys64/.
When using the msys shell, /c/msys64/usr/ is the same as C:/msys64/usr/ which is the same as /usr/ since it tries to blend Linux file organization with windows, and it can sometimes be slightly unintuitive. When you install msys libraries, usually the include files are in C:/msys64/usr/include/ and the libraries are in C:/msys64/usr/lib/. The exception to this is when you have a 64-bit version and a 32-bit version of a program, in which case the headers are in C:/msys64/mingw64/include/ and the libs in C:/msys64/mingw64/lib/ for 64-bit (mingw32 for 32 bit).
In order to build using these, you will need to add the appropriate include paths and library paths. So, to make all 64-bit programs available, you would add the following flags
-IC:/msys64/usr/include -IC:/msys64/mingw64/include -LC:/msys64/usr/lib -LC:/msys64/mingw64/lib
When you compile your own programs from source, you put them wherever you'd like. It is best not to put them in the same directory as the package manager to avoid collisions. Running make install sometimes won't run as seamlessly on msys as it would on linux. In these cases, creating a folder such as C:/msys64/custom/include/ is a safer alternative. See https://unix.stackexchange.com/questions/30/where-should-i-put-software-i-compile-myself for some more insight on this.
im trying to port a c++ project from visual studio 2013 to netbeans on ubuntu. The target is a windows executable, so far im able to compile windows exe files from netbeans using mingw as compiler.
The project needs the Crypto++ library and i only have the .lib version for visual studio. To include the library in netbeans i first need to build the Crypto++ library in the .a format.
Its not clear to me how should i do that.
Ive found informations on how to build the library for linux with mingw but not for cross compilation with mingw. The provided GNUmakefile does not work.
Should i set up a vm with windows and mingw and compile the library that way? Or maybe use the qmake "hack" as suggested here http://www.qtcentre.org/threads/28809-Compiling-amp-using-Crypto-with-mingw-version-of-Qt ? The last good Crypto++ version suggested there is quite old. This is confusing, porting the whole project is easier than having the required library.
Im open to any suggestion.
tldr: how to build libcryptopp.a on linux for the cross compilation of a windows exe project
edit:
for example if i cross compile something there are windows libraries in the /usr/i686-w64-mingw32/lib/ folder like libuser32.a. i need to make the equivalend libcryptopp.a.. sorry if is a bit unclear.
if i simply build using the steps in answer (and in the wiki) i end up with a libcryptopp.a file but i suspect is linux-only, cause if i link that library in netbeans in the .exe file im cross compiling i end up with undefined references to cryptopp stuff everywere. the paths are correct, i suspect the library needs to be replaced with the equivalent libcryptopp.a compatible with crosscompiling.
edit2: im trying to follow the answer down here, now im stuck here. after this command to build cryptopp.
make CXX=/usr/bin/i686-w64-mingw32-gcc INCLUDES="-I /usr/i686-w64-mingw32/include" LIBS="-L /usr/i686-w64-mingw32/lib" CXXFLAGS="-std=c++0x"
and many variations of it i always end up with this error
trap.h:26:25: fatal error: Windows.h: No such file or directory
# include
which makes me think its using the right compiler to make a .a lib file for cross compiling the windows .exe with the lib.
however i dont understand whats going on now with the missing header..:(
Also if i try to link the lib file (used with visual studio) i get a lot of linking errors, undefined reference to cryptopp stuff.
ill offer a symbolic beer (a couple of $ of Bitcoins) if someone finds out how to do it.
Inspired by http://wiki.amule.org/wiki/Cross-compilation_for_windows_with_mingw:
sudo apt-get install mingw-w64
git clone https://github.com/weidai11/cryptopp
cd cryptopp
export TARGET=i686-w64-mingw32
CXX=$TARGET-g++ RANLIB=$TARGET-ranlib AR=$TARGET-ar LDLIBS=-lws2_32 make -f GNUmakefile
I've found informations on how to build the library for linux with mingw but not for cross compilation with mingw.
Its relatively easy...
Get Crypto++ ZIP into MinGW.
Unpack Crypto++ ZIP.
Change directories.
Build the library.
Verify All tests passed.
(1) and (2) can be tricky because Cygwin and MinGW are missing a lot of tools. So curl https://www.cryptopp.com/cryptopp563.zip -o cryptopp563.zip may not work.
For (2), I seem to recall ZIP is missing, so unzip -aoq cryptopp563.zip -d cryptopp-5.6.3 may not work.
At step (4), just perform make static dynamic test and be sure it finished with All tests passed.
I do a lot of testing with Cygwin and MinGW. I have a script that copies Crypto++ into the environments from my Desktop. I have not been able to figure out a way to automate it. A recent question on automating it was closed, so no one can supply an answer (see How to automate software testing for Cygwin and MinGW).
I want to setup an OpenCV project in Linux using Eclipse IDE in C++.
First, I have compiled my own version of OpenCV using the instructions mentioned on the openCV website in my /home/ directory. After this, I wanted to setup a basic show image project using Eclipse IDE following their instructions.
However, I am using OpenSUSE 12.2 and I have an older, preinstalled version of OpenCV in /usr/ and when I build the project and check the linked libraries of OpenCV with the ldd command applied to the generated binary, it points out to the library files from /usr/lib64/.
In order to point out to the compiled library files from my home library I had to modify the LD_LIBRARY_PATH environment variable from .bashrc file:
export LD_LIBRARY_PATH=/home/user/OpenCV/release/lib/:$LD_LIBRARY_PATH
Following this, I started the Eclipse IDE from a terminal with the reinitialized .bashrc file.
After this step it worked. However, is there a way to prioritize the /home/ path over the /usr/ path from Eclipse IDE instead of doing the ./bashrc trick?
Try run your program after setting LD_PRELOAD environmental variable, pointing to your libraries that you want to be loaded first.
You can prepare a script to lauch your program:
export LD_PRELOAD=./your_library.so
./your_program
Can someone tell me if it's possible to compile a project that works with Qt but without installing the entire sdk ? I mean, something like recompile Qt source code and link the libraries or something like this.
I know my problem is weird but I work in special conditions : I am on a linux machine and I have to work on a windows project therefore I use a distant server on windows to compile but I can't install anything on this serveur. I need an idea to have a fully portable folder with Qt who can compile without installing anything.
I hope I was clear in my explications.
Thank you for your help.
I has combined comments in answer.
You need to install compiler (e.g minGW) and Qt Library (as needed version).
You should add into environment variable 'PATH' your path to qmake and compiler.
Start terminal and move to directory with your source code of Qt project.
Run qmake and then exec make (e.g. It, for minGW, is mingw32-make).
For your case, you may choosen 2 way:
Build static Qt Library from source code and use static linking with your project.
Install Qt Library and copy libraries near your project with dynamic linking (recomended).
Is it possible to compile and run OpenGL programs from under Cygwin? If yes, how?
It is possible to compile and run OpenGL programs under Cygwin. I illustrate the basic steps here:
I assume you know OpenGL programming. If not, get the Red Book (The OpenGL Programming Guide). It is mandatory reading for OpenGL anyway.
I assume you have Cygwin installed. If not, visit cygwin.com and install it.
To compile and run OpenGL programs, you need the Cygwin package named opengl. In the Cygwin installer, it can be found under the Graphics section. Please install this package.
Write a simple OpenGL program, say ogl.c.
Compile the program using the flags -lglut32 -lglu32 -lopengl32. (This links your program with the GLUT, GLU and OpenGL libraries. An OpenGL program might typically use functions from all the 3 of them.) For example:
$ gcc ogl.c -lglut32 -lglu32 -lopengl32
Run the program. It's as simple as that!
If the above doesn't work (and it didn't for me), try the following (which did!)
gcc ogl.c -lglut -lglu -lgl
I do not normally post answers this long, but this one is worth it.
I will present a Windows 10 64-bit setup for Cygwin that uses the same libraries as Visual Studio. You will be able to use both development environments with the same code (same includes and libraries), so you can switch between the two as you see fit.
You need three libraries: OpenGL, GLEW, and GLFW.
OpenGL
Visual Studio: The following default locations are valid for current versions of Windows 10 and Visual Studio 2019.
OpenGL static library:
C:\Program Files(x86)\Microsoft Visual Studio\2019\Community\SDK\ScopeCPPSDK\vc15\lib\SDK\lib\opengl32.lib
OpenGL DLL:
C:\Windows\SysWOW64\opengl32.dll
The opengl32.lib library will need to be specified under the VS project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies. The same applies for all other dynamic libraries under Visual Studio. I will not mention it again.
Cygwin:
OpenGL static library default location:
/lib/w32api/libopengl32.a
OpenGL dynamic library (uses the Windows DLL):
C:\Windows\SysWOW64\opengl32.dll
GLEW
Visual Studio: Download 32-bit/64-bit binaries from http://glew.sourceforge.net/ and install in a custom folder, say C:\OpenGL\glew-2.1.0. The same download works for both Visual Studio and Cygwin.
GLEW headers (to #include GL/glew.h):
C:\OpenGL\glew-2.1.0\include
GLEW static library:
C:\OpenGL\glew-2.1.0\lib\Release\x64\glew32.lib
GLEW DLL:
C:\OpenGL\glew-2.1.0\bin\Release\x64\glew32.dll
These can be specified in your VS project's Properties menu.
Cygwin: You can link against this library from Cygwin as-is, meaning you can specify its download directory for the INCS, LIBS, and LDLIBS variables in your Makefile as follows (consistent with the download directory specified above):
GLEW headers directory:
/cygdrive/c/OpenGL/glew-2.1.0/include
GLEW static library directory:
/cygdrive/c/OpenGL/glew-2.1.0/lib/Release/x64
GLEW dynamic library directory:
/cygdrive/c/OpenGL/glew-2.1.0/bin/Release/x64
With these values for INCS, LIBS, and LDLIBS respectively, you can then link using the UNIX naming conventions as shown in the complete Makefile, at the bottom of the post.
GLFW
This can be downloaded at https://www.glfw.org/download. For our 64-bit setup, you need the Windows 64-bit precompiled binaries. You can place it also in a custom folder, say C:\OpenGL\glfw-3.3.4.bin.WIN64. The same download works for both VS and Cygwin.
Visual Studio:
You can specify directly the download locations into your project Properties for headers (to #include GLFW/glfw3.h in your source code) and DLLs (to have VS link against these libraries), respectively.
Cygwin:
For Cygwin, GLFW is trickier, because you can no longer link against it directly from the download location. You need to:
(a) copy the headers, static, and dynamic libraries from the download locations:
C:\OpenGL\glfw-3.3.4.bin.WIN64\include\GLFW\*.h
C:\OpenGL\glfw-3.3.4.bin.WIN64\lib-mingw-w64\*.a
C:\OpenGL\glfw-3.3.4.bin.WIN64\lib-mingw-w64\*.dll
...into your toolchain's (MinGW's) respective locations:
GLFW headers (create the include directory):
/usr/x86_64-w64-mingw32/include/GLFW/*.h
GLFW static libraries:
/usr/x86_64-w64-mingw32/lib/*.a
GLFW dynamic libraries:
/usr/x86_64-w64-mingw32/bin/*.dll
(b) place the dynamic library location into your PATH environment variable, editable in your .bash_profile file in your home directory.
The Makefile for Cygwin is:
CC=/usr/bin/x86_64-w64-mingw32-c++.exe
OPTS=-std=c++11
DEBUG=-g
CFLAGS=-Wall -c ${DEBUG}
INCS= -I.\
-I/cygdrive/c/OpenGL/glew-2.1.0/include\
-I/cygdrive/c/cygwin64/usr/x86_64-w64-mingw32
LIBS= -L/usr/lib\
-L/cygdrive/c/OpenGL/glew-2.1.0/lib/Release/x64\
-L/cygdrive/c/cygwin64/usr/x86_64-w64-mingw32/lib
LDLIBS= -L/bin\
-L/cygdrive/c/OpenGL/glew-2.1.0/bin/Release/x64\
-L/cygdrive/c/cygwin64/usr/x86_64-w64-mingw32\bin
Program.o: Program.cpp
${CC} ${OPTS} ${INCS} -c $<
Program: Program.o
${CC} ${OPTS} ${LIBS} ${LDLIBS} Program.o -lopengl32 -lglew32 -lglew32.dll -lglfw3 -lgdi32 -luser32 -o Program
With this setup, you can use the same exact source code files in both VS and Cygwin. You can compile, link, and run Program.exe from its directory in Cygwin with:
$ make Program
$ ./Program.exe
You can run from VS a Cygwin-compiled program by opening the existing *.exe as an SLN project and running it using the IDE interface. Conversely, you can run the VS executable (created by VS in Project/Debug or Project/Release) directly from the Cygwin command line with the command above.
The includes are:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
No changes whatsoever will have to be made in the source code to switch back and forth b/w VS and Cygwin. Happy coding :-)
I remember doing this once with some success, a few years ago, basically trying to cross compile a small Linux OpenGL C++ program. I do recall problems with Windows OpenGL drivers being behind the times (due to MS's focus on DirectX). I had NVidia OpenGL and DirectX drivers installed on my Windows system, but cygwin/g++ seemed to want to only use the Microsoft OpenGL DLLs, many years old, which do not have the latest support for all the ARB extensions, like shader programs, etc. YMMV.