rogersce / cnpy

library to read/write .npy and .npz files in C/C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Link error

sjsy opened this issue · comments

commented

Hi,
I install the code in Ubuntu 18.04 as following:

$ cmake /home/seyyed/software/cnpy-master
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/seyyed/build

$ make
Scanning dependencies of target cnpy-static
[ 16%] Building CXX object CMakeFiles/cnpy-static.dir/cnpy.cpp.o
[ 33%] Linking CXX static library libcnpy.a
[ 33%] Built target cnpy-static
Scanning dependencies of target cnpy
[ 50%] Building CXX object CMakeFiles/cnpy.dir/cnpy.cpp.o
[ 66%] Linking CXX shared library libcnpy.so
[ 66%] Built target cnpy
Scanning dependencies of target example1
[ 83%] Building CXX object CMakeFiles/example1.dir/example1.cpp.o
[100%] Linking CXX executable example1
[100%] Built target example1

$ sudo make install
[sudo] password for seyyed:
[ 33%] Built target cnpy-static
[ 66%] Built target cnpy
[100%] Built target example1
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/lib/libcnpy.so
-- Installing: /usr/local/lib/libcnpy.a
-- Installing: /usr/local/include/cnpy.h
-- Installing: /usr/local/bin/mat2npz
-- Installing: /usr/local/bin/npy2mat
-- Installing: /usr/local/bin/npz2mat

But when I test the example1.cpp in terminal the following error issued:
$ g++ -o example1 example1.cpp -L/usr/local/lib -lcnpy -lz --std=c++11
$ ./example1
./example1: error while loading shared libraries: libcnpy.so: cannot open shared object file: No such file or directory

So, I compile example1.cpp in Netbeans and the following is the error:

cd '/home/seyyed/NetBeansProjects/test_cnpy'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/seyyed/NetBeansProjects/test_cnpy'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/test_cnpy
make[2]: Entering directory '/home/seyyed/NetBeansProjects/test_cnpy'
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/test_cnpy build/Debug/GNU-Linux/main.o /usr/local/lib/libcnpy.a /usr/local/lib/libcnpy.so
build/Debug/GNU-Linux/main.o: In function void cnpy::npz_save<double>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double const*, std::vector<unsigned long, std::allocator<unsigned long> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/seyyed/software/cnpy-master/cnpy.h:171: undefined reference to crc32'
/home/seyyed/software/cnpy-master/cnpy.h:172: undefined reference to crc32' build/Debug/GNU-Linux/main.o: In function void cnpy::npz_save(std::__cxx11::basic_string<char, std::char_traits, std::allocator >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, char const*, std::vector<unsigned long, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator >)':
/home/seyyed/software/cnpy-master/cnpy.h:171: undefined reference to crc32' /home/seyyed/software/cnpy-master/cnpy.h:172: undefined reference to crc32'
build/Debug/GNU-Linux/main.o: In function void cnpy::npz_save<std::complex<double> >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::complex<double> const*, std::vector<unsigned long, std::allocator<unsigned long> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/seyyed/software/cnpy-master/cnpy.h:171: undefined reference to crc32'
build/Debug/GNU-Linux/main.o:/home/seyyed/software/cnpy-master/cnpy.h:172: more undefined references to crc32' follow /usr/local/lib/libcnpy.a(cnpy.cpp.o): In function load_the_npz_array(_IO_FILE*, unsigned int, unsigned int)':
cnpy.cpp:(.text+0x1586): undefined reference to inflateInit2_' cnpy.cpp:(.text+0x15e8): undefined reference to inflate'
cnpy.cpp:(.text+0x15fd): undefined reference to `inflateEnd'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:66: recipe for target 'dist/Debug/GNU-Linux/test_cnpy' failed
make[2]: *** [dist/Debug/GNU-Linux/test_cnpy] Error 1
make[2]: Leaving directory '/home/seyyed/NetBeansProjects/test_cnpy'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/seyyed/NetBeansProjects/test_cnpy'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 278ms)

Please help me.
Thanks.

had the same problem on Ubuntu 16.04.
solved it like this (assuming that libcnpy.so is installed in /usr/local/lib):

  • add a file named cnpy.conf to /etc/ld.so.conf.d
  • the content of this file should be path/to/install/dir so default would be /usr/share/lib/
  • run sudo ldconfig

after changing to your example-directory, do

$ g++ -o example1 example1.cpp -L/usr/local/lib -lcnpy -lz --std=c++11
$ ./example1

again and it should work.
I got the answer from here: https://stackoverflow.com/questions/4078292/compiled-c-program-raises-cannot-open-shared-object-file-on-another-system-t