gnhlug-discuss-boun...@mail.gnhlug.org wrote on 05/10/2010 10:21:50 AM: > Fellow list members, I've got a linux linking problem, which has me > stumped. Since I've been coding mostly in python, lately, my 'C' brain > has atrophied... > > I've got a C (umm actually C++) program that won't link to some ATLAS > libraries which I recently compiled. The program itself will compile, > link and run if I link to the baseline (non-optimized) ATLAS libraries. I > think it even gives the expected result, as an added bonus! > > However, if I use "/usr/local/atlas/include/cblas.h" instead of the system > "/usr/include/cblas.h" in the code snippet below, > > extern "C"{ > #include "/usr/local/atlas/include/cblas.h" > } > > the build reports: > $ ./build_cblas_test > Building cblas1 > /tmp/ccSMmtzW.o: In function `main': > cbas_tb.cpp:(.text+0x899): undefined reference to `cblas_zgemm' > collect2: ld returned 1 exit status > Build complete > > My build file --> not a make file yet because it is just a one liner, is: > > g++ -O3 -m64 -I/usr/local/atlas/include -L/usr/local/atlas/lib -lcblas -lm > -Wall -Wcast-qual -o cblas1 cblas_tb.cpp > > I've tried copying the include file and lib file and stuffing them in the > same directory as the cpp file, but to no avail. (Yes I modified the > command above.) > > Before anyone asks, yes, there are files at the locations. The new > cblas.h file looks very close to the old, although I have not run a diff
> on them. ( cblas_zgemm is in the new header, I looked.) The library is > static. Is there a tool to look inside an .a file? > > I figure the problem is probably an operator error, sigh, but I'm not sure > what it is. If someone could point me in the right direction, I'd > appreciate it. Assume nothing - it is probably basic. :( > > I can post the code if people think it would help. (Just didn't want to > make this email any longer than necessary.) > For the sake of completeness: here is the source: // ==== start of source file ==== /* ** cblas_tb.cpp -- an initial stab at implementing a matrix matrix multiply using the blas library. This is a precursor file for LAPACK Origin Date: 5 May 2010 */ #include <stdio.h> #include <complex> extern "C"{ #include "/usr/local/atlas/include/cblas.h" } using namespace std; using std::complex; typedef complex<double> dcomp; /* Define complex double data type */ int main(void) { int i, j, M, N; M = 5; N = 5; dcomp A[M][N]; // init A to eye(5), sort of... printf("Initial value of A\n"); for(i=0; i<M; i++) { for (j=0; j<N; j++) { if (i==j) { A[i][j] = dcomp(1.0, 0.1); } else { A[i][j] = dcomp(0.0, 0.0); } printf("A[%i][%i]= %f, %f\n", i, j, real(A[i][j]), imag(A[i][j])); } } printf("\n"); dcomp C[M][N]; double NN = 1.0/double(N); dcomp alpha = dcomp(NN, 0.0); dcomp beta = dcomp(0.0, 0.0); int m,k,n; // matrix dimensions, A = [m x k], B = [k x n] m = 5; k = 5; n =5; int ldA, ldB, ldC; ldA = 5; ldB = 5; ldC = 5; cblas_zgemm(CblasRowMajor, CblasNoTrans, CblasConjTrans, m, n, k, &alpha, A, ldA, A, ldB, &beta, C, ldC); printf("Computed value for C\n"); for (i=0; i<5; i++) { for (j=0; j<5; j++) { printf("C[%i][%i]= %f, %f\n", i, j, real(C[i][j]), imag(C[i][j])); } } return 0; } // ==== end of source file ================ Adding a -v to the compile reveals: $ ./buildcblas_test Building cblas1 Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) COLLECT_GCC_OPTIONS='-O3' '-m64' '-v' '-I/usr/local/atlas/include' '-L/usr/local/atlas/lib/' '-Wall' '-Wcast-qual' '-o' 'cblas1' '-shared-libgcc' '-mtune=generic' /usr/lib/gcc/x86_64-linux-gnu/4.4.3/cc1plus -quiet -v -I/usr/local/atlas/include -D_GNU_SOURCE cblas_tb.cpp -D_FORTIFY_SOURCE=2 -quiet -dumpbase cblas_tb.cpp -m64 -mtune=generic -auxbase cblas_tb -O3 -Wall -Wcast-qual -version -fstack-protector -o /tmp/ccMNCUj8.s GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (x86_64-linux-gnu) compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../x86_64-linux-gnu/include" ignoring nonexistent directory "/usr/include/x86_64-linux-gnu" #include "..." search starts here: #include <...> search starts here: /usr/local/atlas/include /usr/include/c++/4.4 /usr/include/c++/4.4/x86_64-linux-gnu /usr/include/c++/4.4/backward /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include-fixed /usr/include End of search list. GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (x86_64-linux-gnu) compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 88858f45841827736473e527a4e9ab10 COLLECT_GCC_OPTIONS='-O3' '-m64' '-v' '-I/usr/local/atlas/include' '-L/usr/local/atlas/lib/' '-Wall' '-Wcast-qual' '-o' 'cblas1' '-shared-libgcc' '-mtune=generic' as -V -Qy --64 -o /tmp/cciYxVSy.o /tmp/ccMNCUj8.s GNU assembler version 2.20.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.20.1-system.20100303 COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/ LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../:/lib/:/usr/lib/:/usr/lib/x86_64-linux-gnu/ COLLECT_GCC_OPTIONS='-O3' '-m64' '-v' '-I/usr/local/atlas/include' '-L/usr/local/atlas/lib/' '-Wall' '-Wcast-qual' '-o' 'cblas1' '-shared-libgcc' '-mtune=generic' /usr/lib/gcc/x86_64-linux-gnu/4.4.3/collect2 --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o cblas1 -z relro /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbegin.o -L/usr/local/atlas/lib/ -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../.. -L/usr/lib/x86_64-linux-gnu -lcblas /tmp/cciYxVSy.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crtn.o /tmp/cciYxVSy.o: In function `main': cblas_tb.cpp:(.text+0x899): undefined reference to `cblas_zgemm' collect2: ld returned 1 exit status Build Complete If I look inside of /usr/local/atlas/lib/libcblas.a using elfreader ( thanks Michael! ) I get: $ readelf -a libcblas.a | grep cblas_zgemm File: libcblas.a(cblas_zgemm.o) 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS cblas_zgemm.c 24: 0000000000000000 1533 FUNC GLOBAL DEFAULT 1 cblas_zgemm There is something there. Somewhat reasonable stuff inside of libcblas.a... Any ideas? TIA -Bruce ****************************** Neither the footer nor anything else in this E-mail is intended to or constitutes an <br>electronic signature and/or legally binding agreement in the absence of an <br>express statement or Autoliv policy and/or procedure to the contrary.<br>This E-mail and any attachments hereto are Autoliv property and may contain legally <br>privileged, confidential and/or proprietary information.<br>The recipient of this E-mail is prohibited from distributing, copying, forwarding or in any way <br>disseminating any material contained within this E-mail without prior written <br>permission from the author. If you receive this E-mail in error, please <br>immediately notify the author and delete this E-mail. Autoliv disclaims all <br>responsibility and liability for the consequences of any person who fails to <br>abide by the terms herein. <br> ****************************** _______________________________________________ gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/