I am working on Windows 10 64-bit using MSYS2 with the 64-bit toolchain. In the MSYS2 terminal I found and installed the following packages after searching for them with pacman -Ss,
mingw64/mingw-w64-x86_64-openblas 0.2.20-2
mingw64/mingw-w64-x86_64-lapack 3.6.1-1
mingw64/mingw-w64-x86_64-arpack 3.5.0-1
I took an example fortran source file from the Intel MKL library examples; I copied the dgelsx.f file to a folder in my msys home directory. I compile (in the mingw64 terminal) with
gfortran dgelsx.f -o dgelsx -llapack -lblas
it compiles without any complaint, but when I attempt to run it, I get the error
C:/msys64/home/k_chu/lapacktext/dgelsx.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
Why is this happening? I haven't attempted to deal with an arpack example yet until I get this working. Also if I do get all of this working, will it be possible to use the arpack libraries in Microsoft Visual Studio with the Intel ifort compiler? I tried copying the .dll files in /msys64/mingw64/bin into my MSV project folder but no luck, same with the .a and .dll.a files in the /msys64/mingw64/lib.
Please use dependency walker (http://www.dependencywalker.com) to locate the .dll, which the program cannot find on the path. Or compile with -static-libgcc or -static-libstdc++ to avoid dependencies at runtime.
Related
I am compiling a C++ program on windows under MSYS2 MinGW and I am using the libpqxx library, the program compiles fine but when I go to run it from file explorer I get the following error
The Procedure entry pointstd::from_chars(char const*, char const*, double&, std::chars_format) could not be located in the dynamic link library libpqxx-7-7.dll
this program runs without any errors if I run it from the MSYS2 MinGW terminal (By executing ./main.exe) but I would like the program to work without having to install MSYS2. I have the libpqxx library installed. I am using the following commands to compile the program
g++ main.cpp -o main libpq.lib -lpqxx
pkg-config --cflags --libs gtk+-3.0
(this program was developed on linux and I am using the gtk library)
(edit) Here is the folder structure that I have, the required dll is contained in the folder already, if I remove the dll then I get a file not found error
any help would be greatly appreciated
I have fixed the problem, I just needed to add a few more dll files to the directory in which my program resides and now it starts!
the dll files required are:
libintl-8.dll
libstdc++-6.dll
these dll files can be found in the bin folder under the mingw64 folder
Thanks to #HolyBlackCat for pointing me in the right direction (telling me that I need more dlls)
I wrote a simple HelloWorld console application and compiled it on Windows 7 with MinGW compiler using one of these commands:
gcc -Wall -pedantic Hello.c -o Hello.exe
g++ -Wall -pedantic Hello.cpp -o Hello.exe
However the compiler links some own dynamic libraries into the app and when i copy the executable into another computer with Windows 7, which does not have MinGW installed, i'm getting missing library error. On Linux this problem is solved by package system, which automatically installs all needed libs, but in Windows you surely don't want to tell your users to install MinGW in order to run your program.
So my question is: How do i link all libraries properly and what else do i have to do to make my application run independently?
Although i believe, this must be a fundamental problem to all Windows programmers, i have been unable to find any answers on the internet (maybe i just don't know how and what to search).
It was in the FAQ at some stage, but now I seem to find it only on this page:
Why I get an error about missing libstdc++-6.dll file when running my program?
GCC4 dynamically link to libgcc and libstdc++ libraries by default
which means that you need a copy of libgcc_s_dw2-1.dll and
libstdc++-6.dll files to run your programs build with the GCC4 version
(These files can be found in MinGW\bin directory). To remove these DLL
dependencies, statically link the libraries to your application by
adding "-static-libgcc -static-libstdc++" to your "Extra linking
options" in the project settings.
Try this,
g++ -static-libgcc -static-libstdc++ -Wall -pedantic Hello.cpp -o Hello.exe
I'm afraid to say that with all of the applications installed on my machine, it's easy to identify which ones were built with MinGW. The telltale sign is a folder filled with libraries.
Check to see if the libraries that you need are distributable, and then simply include them in your .exe directory.
Although you may have other applications installed on user's machine, and some of them may contain the libraries that you need, there's a good chance that your application wont be compatible with them. This is why asking your users to install MinGW would be unlikely to work anyways.
I'm trying to get back to C++ using Mingw and Netbeans but all released .exe requires some .dll files if ran on another PC.
What should I do to add those library to the released .exe file. [I do not have too much experience in real C++ programming]
Please tell us what dll's are missing. but often you can find them in the bin folder of mingw. If you release your program, put those dll's where your exe is.
Alternative: use static linkage
Edit:
You can get this file from the bin folder of your mingw installation. Copy it to your exe
Compile with linker flags: -static-libstdc++ and -static-libgcc
I'm trying to get started with a domain-specific language (C++ extension) for image processing called Halide.
Following the Halide README, here's what I've tried:
Downloaded the Ubuntu 12.04 Halide binary, and extracted in a directory called ~/halide.
In the ~/halide directory, I created hello_halide.cpp, as described in the Using Halide section of this page.
Tried to compile hello_halide.cpp:
g++-4.6 -std=c++0x hello_halide.cpp -L halide -lHalide -ldl -lpthread -o hello_halide
But, g++ can't find libhalide:
/usr/bin/ld: error: cannot find -lHalide
Tried adding ~/halide to my $PATH and $LD_LIBRARY_PATH, but this didn't help.
How can I compile this basic hello_halide.cpp Halide program?
Notes:
CUDA is one of Halide's dependencies. I have CUDA installed, and I can compile/run CUDA programs.
I'm using Ubuntu 12.04.
My g++ version is 4.6.3.
-L halide tells the linker to look for the library in the subdirectory halide. In this case that means that your source file hello_halide.cpp should be in a folder ~/myfolder/, and the library libHalide.so at ~/myfolder/halide/libHalide.so (or .a if it's static). If it's somewhere else, pass an absolute path to -L.
Your idea of setting LD_LIBRARY_PATH or PATH does not work since the latter is for directories that will be searched for executables and the former is for directories that will be searched for shared libraries when you launch an executable that needs shared libraries.
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.