g++ doesn't recognize the file format of a dll - dll

I am on Windows, and I am using the version of g++ that comes with mingw-64. I have a file on my computer called lua51.dll. When I try to run the following command :
g++ -shared -fPIC -o stuff.dll -llua51 stuff.cpp
I get the following error:
C:/Program Files/LOVE/lua51.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
make: *** [main] Error 1
How can I fix this? Please let me know if more information is needed; I am a complete beginner to compilation.

This is an issue you get when you try to include a 64-bit library when running a 32-bit version of g++ or even gcc.
I thought that that the version of g++.exe that comes with mingw-64 would produce 64-bit code, but it turns out this isn't true; it still only produces 32-bit code. In my case, lua51.dll is 64-bit, which is an issue since I was using the version of g++ that produces 32-bit code.
Instead, you need to use x86_64-w64-mingw32-g++.exe, which can be found in the same folder as g++.exe. This is the version of g++ that will produce 64-bit code.

Related

msys2 (msys64) cannot find -lcrypt

I have msys2 (msys64) https://www.msys2.org/ and am compiling some older code in gcc, but get "cannot find -lcrypt", -lcrypt is declared in the makefile, as crypt is cited in the code.
The only version of crypt library I can get to get to run is -lcrypt32 which is a library in msys2, but this doesn't seem to offer the support for crypt so I then get crypt errors. Does anyone know how to get the normal crypt recognized in msys2? I assume it's relying on mingw, I also recall from a long while back that mingw doesn't support lcrypt, but I could be wrong.
/usr/lib/gcc/x86_64-pc-msys/6.4.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lcrypt
collect2: error: ld returned 1 exit status
make: *** [Makefile:260: arch] Error 1
MSYS2 does not appear to ship a MinGW version of libcrypt. But as long as you just want to run this locally and do not need to redistribute it, you could compile it with the MSYS2 GCC. There is libcrypt for it. Just run...
pacman -S msys/libcrypt-devel
And then that should work:
gcc test.c -lcrypt

How to make cmake identify correct version in centos 6 terminal?

After a very long and lengthy process of trying to get Emscripten going. I'm stuck trying to build fastcomp.
cmake .. -DCMAKE_BUILD_TYPE=Release
-DLLVM_TARGETS_TO_BUILD="X86;JSBackend" -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DCLANG_INCLUDE_TESTS=OFF
It gives this error:
CMake Error at cmake/modules/CheckCompilerVersion.cmake:12 (message):
Host GCC version must be at least 4.8!
I've installed devtools 2 and actiavted the toolset.
gcc --version reads as using gcc 4.8.2, but it just won't go.
I've also tried:
export CC=/opt/rh/devtoolset-2/root/usr/bin/gcc
export CXX=/opt/rh/devtoolset-2/root/usr/bin/c++
export CPP=/opt/rh/devtoolset-2/root/usr/bin/cpp
What am I doing wrong?
I had this same problem until I recompiled a recent version of cmake with the newer version of gcc already "activated".
Then, with the CC, CXX and CPP environment variables also set to the appropriate paths, cmake then stopped giving that "Host GCC version must be at least 4.8!" error.

cannot execute binary file error that I scpd to a different computer

I scp'd a Unix executable file into my work computer and am receiving an error when trying to run it. If I type in:
./cmpDNA 4 5 0.3 > results/results4_5_0.3.txt &
where cmpDNA is my program, 4 5 0.3 are input parameters and results/results4_5_0.3.txt is my output file, this is the error I receive:
-bash: ./cmpDNA: cannot execute binary file
I compiled in on my OS X computer using g++ and made sure to include my -m32 for a 32 bit build as the target computer is 32-bit Ubuntu. Typing:
file cmpDNA
gets:
cmpDNA: Mach-O executable i386
So I'm not sure why it won't execute. I've been looking for awhile but I can't find any answers that solve my problem. All users have executable permissions as well. Here were all of my compile options if that helps:
g++ -Wall -std=gnu++0x -o cmpDNA -m32 files.cpp
Thanks!
Can not compile on OS X without using a cross compiler and run on Ubuntu. Here is the answer that I found:
Compiling C Program on OS X to Run on Ubuntu

Lapack undefined reference

I am new to g++ and lapack, and attempting to use them. I encountered a problem when I tried to compile the following naive code
#include <lapackpp.h>
int main()
{
LaGenMatDouble A;
return 0;
}
If I run the command
$g++ -L/usr/local/lib -llapackpp test2.cpp
where test2.cpp is the name of the cpp file, the terminal would give an error:
test2.cpp:1:22: fatal error: lapackpp.h: No such file or directory
But if I run the command:
$g++ -I/usr/local/include/lapackpp -L/usr/local/lib -llapackpp test2.cpp
the terminal would give an error:
/tmp/ccUi11DG.o: In function `main':
test2.cpp:(.text+0x12): undefined reference to `LaGenMatDouble::LaGenMatDouble()'
test2.cpp:(.text+0x23): undefined reference to `LaGenMatDouble::~LaGenMatDouble()'
collect2: ld returned 1 exit status
BTW, if I run the command
$pkg-config lapackpp --libs
the result is
-L/usr/local/lib -llapackpp
Could you please help me solve this? Thanks in advance!
Lapack requires fortran libraries, so that's where the -lgfortran comes from. Moreover, it appears the exact way to provide that library for the compiler depends on the Linux distriburion. From the documentation:
Requirements
This package requires the packages "blas", "lapack" (without the "++"), and a Fortran compiler. On most Linuxes these are available as pre-compiled binaries under the name "blas" and "lapack". For SuSE 10.x, the Fortran compiler is available as package "gfortran". For SuSE 9.x, the Fortran compiler is available as package "gcc-g77".
Not sure why pkg-config lapackpp --libs does not list -lgfortran
The -I/usr/local/include/lapackpp specifes the lapackpp-related header files. Without it the compiler cannot find lapackpp.h when you try to include it (#include <lapackpp.h>) -- see the compiler error in your question
I finally solved the problem but would still wonder why it has to be so.
The only command that can link cpp file to lapackpp library is:
g++ foo.cpp -o foo -lgfortran -llapackpp -I/usr/local/include/lapackpp
It would not work without -lgfortran, or with -I/usr/local/include/lapackpp replaced by -L/usr/local/lib.
Does anyone have an answer?

g++ issue with Magick++ and cygwin

When I try to compile a simple c++ file using Magick++ and cygwin, I keep getting this result:
$ g++ -o imageTest imageTest.cpp `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
g++: unrecognized option `-no-undefined'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -ldpstk
collect2: ld returned 1 exit status
I installed ImageMagick through the cygwin gui setup.
GraphicsMagick and ImageMagick are two different libraries. If you want to build your program using ImageMagick, as you state, it's just a matter of changing
GraphicsMagick++-config
into
Magick++-config
This should work. As for GraphicsMagick, it looks like the current -devel library in Cygwin is broken, as it requires a library (libdpstk) which is no longer available. (Have a look here if you are interested.)