Trouble building a MIPS compatible C static library - cross-platform

I'm trying to build a C static library (.a) that is compatible with a MIPS processor (I'm working in an embedded system).
To do so I tried to execute the following commands (obs: I'm using the mipsel-unknown-elf tool):
mipsel-unknown-elf-gcc -o math.o -c math.c
(No erros followed this command)
mipsel-unknown-elf-gcc -archive -o libmath.a math.o -lm
With this command I got the following error message:
cannot find -lm
collect2: ld returned 1 exit status
By getting this message I tried to add a -L/path argument:
mipsel-unknown-elf-gcc -archive -o libmath.a math.o -L/usr/lib/i386-linux-gnu -lm
But then I got the following error:
skipping incompatible /usr/lib/i386-linux-gnu/libm.a when searching for -lm
cannot find -lm
collect2: ld returned 1 exit status
Does anyone knows what's going on?

Your cross compiler distribution should include a MIPS libm.a. I just checked and I found several libm.a versions in my installation of CodeSourcery mips-linux-gnu-gcc. I don't have mipsel-unknown-elf-gcc installed, so I can't check that. If the mips-linux-gnu- version of libm.a is self contained, you might try using that version.

Related

g++ doesn't recognize the file format of a 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.

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

wxWidgets 2.9.4 + Xcode 4.5.2 - Can't make it work

I'm having troubles trying to use wxWidgets 2.9.4 and Xcode 4.5.2, I get all sort of errors in the way.
First of all, I think I installed wxWidgets correctly, because every sample and demo run just fine. The problem is when I try to create an Xcode project.
When I follow the wxWidgets tutorial changing the build settings as follows:
Paste the --cppflags in "Other C++ Flags"
Paste the --libs in "Other Linker Flags" (REMOVING THE -L)
Change the compiler to GCC
I get:
ld: library not found for -lwxregexu-2.9
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I follow the http://zebratale.tumblr.com tutorial (seems more detailed to me)
I get:
ld: library not found for -lwx_osx_cocoau_xrc-2.9
clang: error: linker command failed with exit cod 1 (use -v to see invocation)
I'm completely lost and I'd appreciate any help
------------UPDATE------------------------
I just found out that it's possible to compile it using the terminal command:
g++ -o main main.cpp './../../build-cocoa-debug/wx-config --debug --cxxflags --libs'
So I guess the problem is the compiler Xcode is using. But when I change it to LLMV GCC 4.2, I get the same error (YES, as if it was still using clang)
To change the compiler I went to build settings->build options->compiler for c/c++/objective-c and changed it.
---------UPDATE2-----------------
Even now that I changed the compiler on Xcode the error is:
ld: library not found for -lwx_osx_cocoau_xrc-2.9
collect2: ld returned 1 exit status
Command /Applications/Xcode.app/Contents/Developer/usr/bin/llvm-g++-4.2 failed with exit code 1
First, use --cxxflags (C++ compiler flags), not --cppflags (C preprocessor flags).
Second, why do you remove -L? Of course the linker can't find the libraries if you remove the option telling it where they are.

pthread library inclusion at (linking?) step

I'm trying to compile a program provided to me. I noticed in the Makefile it runs the command
g++ -o test [...] -lpthread
I noticed the pthread library file is in /lib/libpthread.so.0 , but when I try to make the target, it gives me this error:
/usr/bin/ld: cannot find -lpthread
collect2: ld returned 1 exit status
how do I fix this?
In order to use -lpthread, you need a libpthread.a library archive and this is for static linking. libpthread.so.0 is a shared object which means it is used for dynamic linking. See GCC Link Options

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?