mex files in 32-bit matlab on 64-bit Ubuntu - matlab

I am trying to compile object detection program from http://people.cs.uchicago.edu/~rbg/latent/, without any luck, however.
I installed 64-bit Ubuntu 12.10, 32-bit MATLAB 2012a. I also have gcc compiler
ivan#ubuntu:~$ gcc --version
gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
Here is the error I get
EDU>> demo
compiling the code...
Warning: You are using gcc version "4.7.2-2ubuntu1)". The version
currently supported with MEX is "4.4.6".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgomp.so when searching for -lgomp
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgomp.a when searching for -lgomp
/usr/bin/ld: cannot find -lgomp
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
mex: link of ' "bin/fv_cache.mexglx"' failed.
Warning: Maybe you need to call fv_cache('unlock') first?
> In fv_compile at 50
In compile at 48
In demo at 5
Warning: You are using gcc version "4.7.2-2ubuntu1)". The version
currently supported with MEX is "4.4.6".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
mex: link of ' "bin/cascade.mexglx"' failed.
Error using mex (line 206)
Unable to complete successfully.
Error in cascade_compile (line 43)
eval(mexcmd);
Error in compile (line 50)
cascade_compile(opt, verb);
Error in demo (line 5)
compile;
I suspect it has something to do with missing 32-bit libraries. I am new to unix systems so I might not have included all the information you need to know.
Update:
New errors look like
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgomp.so when searching for -lgomp
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgomp.a when searching for -lgomp
/usr/bin/ld: cannot find -lgomp
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
mex: link of ' "bin/fv_cache.mexglx"' failed.
I tried to create a symbolic link
sudo ln -s /usr/lib/i386-linux-gnu/libc.so.6 /usr/lib/libc.so.6
However it didn't solve the problem

Try looking for crti in your system first:
~$ sudo find /usr/ -name crti*
/usr/lib/x86_64-linux-gnu/crti.o
/usr/lib32/crti.o
If it's not there, or the lib32 version, install libc6-dev:
~$ sudo apt-get install libc6-dev
If it is there, try adding the library location:
LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH
export LIBRARY_PATH
See also these posts in Ask Ubuntu and SO for relevant questions and help.

Related

what's the properly cmakelists.txt for libpq library

I am trying to use libpq postgresql.
https://pgpedia.info/l/libpq.html
I copied the exact code.Trying to understand how to use cmake.
I am using Clion. (I guess the IDE doesn't matter.
The following part is CMakeLists.txt.
cmake_minimum_required(VERSION 3.23) project(test111 C)
set(CMAKE_C_STANDARD 99)
add_executable(test111 main.c)
find_package(PostgreSQL REQUIRED)
#target_include_directories(ecpg PUBLIC ${/usr/include/postgresql})
#target_link_libraries(ecpg PUBLIC ${PostgreSQL_LIBRARIES}
target_link_libraries(test111 PUBLIC ${/usr/lib/postgresql/15/lib})
#target_include_directories(MyTarget PRIVATE ${/usr/include/postgresql})
include_directories("/usr/include/postgresql")
using pg_config | rg PKG command return:
PKGINCLUDEDIR = /usr/include/postgresql
PKGLIBDIR = /usr/lib/postgresql/15/lib
Also mark this related to postgresql. I copy the exact code from https://pgpedia.info/l/libpq.html to c_libpqtest.c
gcc -o c_assert -I/usr/include/postgresql -L/usr/lib/postgresql/15/lib c_libpqtest.c
Still errors:
/usr/bin/ld: c_libpqtest.c:(.text+0x70): undefined reference to `PQstatus'
/usr/bin/ld: c_libpqtest.c:(.text+0x80): undefined reference to `PQerrorMessage'
/usr/bin/ld: c_libpqtest.c:(.text+0xbd): undefined reference to `PQexec'
/usr/bin/ld: c_libpqtest.c:(.text+0xd7): undefined reference to `PQgetvalue'
/usr/bin/ld: c_libpqtest.c:(.text+0xeb): undefined reference to `PQclear'
/usr/bin/ld: c_libpqtest.c:(.text+0xf7): undefined reference to `PQfinish'
collect2: error: ld returned 1 exit status
Update: The following compile ways will work. Reference: https://riptutorial.com/postgresql/example/8018/accessing-postgresql-with-the-c-api
gcc -Wall -o c_libpq -I/usr/include/postgresql -L/usr/lib/x86_64-linux-gnu c_libpqtest.c -lpq
gcc -Wall -o c_libpq -I "$(pg_config --includedir)" -L "$(pg_config --libdir)" c_libpqtest.c -lpq
gcc -o c_libpq -I/usr/include/postgresql -L/usr/lib/postgresql/14/lib c_libpqtest.c -lpq
Shared libpq library in /usr/lib/x86_64-linux-gnu
So overall I know how to use gcc command line solve this problem. I still don't know how to use cmake to solve the problem...
CMake provides a FindPostgreSQL.cmake module file, and it defines an imported target since 3.14: https://cmake.org/cmake/help/latest/module/FindPostgreSQL.html
So the most robust approach is:
cmake_minimum_required(VERSION 3.14)
project(myproject LANGUAGES C)
find_package(PostgreSQL REQUIRED)
add_executable(myapp main.c)
target_link_libraries(myapp PRIVATE PostgreSQL::PostgreSQL)

/usr/bin/ld: cannot find -lmat while importing MAT-file in fortran with fintrf.h

I try to compile a matlab "fintrf.h" based fortran code with gfortran to import a MAT-file in a fortran program. Here is the compiling commands:
gfortran -mcmodel=medium -Ofast $1.F90 -I/mnt/f/MATLAB/extern/include/ -L/mnt/f/MATLAB/bin/win64/ -cpp -lmat -lmx -Wl,-rpath /mnt/f/MATLAB/bin/win64/ -o $1.exe
And I am given these errors:
/usr/bin/ld: cannot find -lmat
/usr/bin/ld: cannot find -lmx
but I am sure the "libmat.dll" and "libmex.dll" is in "../win64/" dictionary. Can you help me out? Thanks
You want -L to point to the directory containing the corresponding .lib files.
So something like:
gfortran ... -L/mnt/f/MATLAB/extern/lib/win64/mingw64 -lmat -lmx ...

ld: cannot find -lc when linking as elf i386

I'm stumped on this.
I am using Ubuntu 18.04. I want link together an executable as a 32-bit program, for educational purposes.
My ld default search paths are all for the 64bit toolchain, so I think I need to invoke ld with additional library search paths since I want to link as 32bit. It can not find libc for some reason.
ld -mi386linux -L/lib/i386-linux-gnu/ -lc -o cc codechef.o -dynamic-linker /lib/i386-linux-gnu/ld-linux.so.2
This gives me the error ld: cannot find -lc
I have verified that libc.so.6 file does exist at /lib/i386-linux-gnu/libc.so.6
adding --verbose to my command reveals: attempt to open /lib/i386-linux-gnu//libc.a failed Why does my ubuntu installation not have this file but does have the .so?

How to fix linking errors with gfortran compiler?

I downloaded Eclipse and Cygwin for windows 7 64 bit. I wrote the next Fortran program:
program main
print*, 'Hello World'
end program main
and got the next error when I tried to build the program:
make all
Building target: examples
Invoking: GNU Fortran Linker
gfortran -o "examples" ./main.o
gfortran: fatal error: -fuse-linker-plugin, but cyglto_plugin.dll not found
compilation terminated.
makefile:29: recipe for target 'examples' failed
make: *** [examples] Error 1
I looked for the file cyglto_plugin.dll, and found it in the folder:
C:\cygwin64\lib\gcc\x86_64-pc-cygwin\4.9.3
I tried to add this folder to the PATH environment variable but still got the same error.
Searching the web I found out that the problem can be solved by installing as a dependency the library cyglto_plugin.dll, which is used for Link-Time-Optimization, and can be found in the package gcc-core. However, I have no idea how to do it, can someone instruct me please ?
Using the command prompt I disabled this library by typing:
$ gfortran main.f90 -fno-use-linker-plugin -o main
doing so I got a bunch of new errors:
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find crtbegin.o: No such file or directory
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lquadmath
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/../../../../x86_64-pc-cygwin/bin/ld: cannot find crtend.o: No such file or directory
Do someone has an idea how to fix these errors ?

Symbolic link to compile the code using 32-bit libraries in 64-bit Ubuntu 12.10

I am trying to mex C code using 32-bit 2012a Matlab on 64-bit Ubuntu 12.10
I've downloaded all possible libraries (gcc 4.7, build-essential,libs-32 etc.) however I am getting the following error
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgomp.so when searching for -lgomp
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgomp.a when searching for -lgomp
/usr/bin/ld: cannot find -lgomp
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
I've found that this problem can be solved by setting symbolic link from 64-bit libraries to the 32-bit ones. I tried to create different links but couldn't finish the compilation.
Thank you in advance.
UPDATE 1
gcc-multilib was missing, so after
sudo apt-get install gcc-multilib
I get the following errors
Warning: You are using gcc version "4.7.2-2ubuntu1)". The version
currently supported with MEX is "4.4.6".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
My mexopts.sh looks like
CC='gcc'
CFLAGS='-ansi -D_GNU_SOURCE'
CFLAGS="$CFLAGS -fPIC -pthread -m32"
CFLAGS="$CFLAGS -fexceptions"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64"
CLIBS="$RPATH $MLIBS -lm"
COPTIMFLAGS='-O -DNDEBUG'
CDEBUGFLAGS='-g'
CLIBS="$CLIBS -lstdc++"
the -m32 is there, however I am not sure if it should be written in that way.
Can someone elaborate on how to edit mexopts.sh to make matlab look at 32-bit libraries?
UPDATE 2
after looking at Linking using g++ fails searching for -lstdc++
I tried to install g++-multilib
sudo apt-get install g++-multilib
Now, errors have the form:
/usr/bin/ld: i386:x86-64 architecture of input file `bin/fv_cache.o' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `bin/obj_func.o' is incompatible with i386 output
...
First make sure you can build 32-bit executable from command prompt by executing gcc (more info here: 32bit application on 64 bit Linux)
In matlab command prompt execute mex -setup and choose gcc as a compiler. At the end you will get a message about location of 'mexopts.sh' (usually ~/.matlab//mexopts.sh)
Try to "mex".
If not successful open mexopts.sh and check if option -m32 is in CFLAGS. If not, add it.