OSX 10.11.6 lldb says Breakpoint 1: no locations (pending) - c

I have what should be an elementary activity with C, Make and lldb on OSX, that seems to not be working as-specified in the documentation. The simple C-coding exercise to learn the "lldb" Debugger, is Exercise-4 from "Learning C The Hard Way" (Shaw, Zed A., 2015), so it's a well-worn, no complexities example of how this should work. Only OSX doesn't behave the way its Man and Help pages say it should.
Is there something fundamentally missing from the Makefile? Is the documentation giving me incorrect syntax? Is there a bug with this version of OSX or the compiler, or lldb? Can you just not set Breakpoints on the main() method in C on OSX, so the exercise is fundamentally flawed and no-one noticed for two years?
Thanks for taking the time to look it over ...
Here's the whole use-case output:
My-MacBook-Pro:Exercises Me$ ls -als total 48
0 drwxr-xr-x 7 Me staff 238 Mar 12 20:56 .
0 drwxr-xr-x 8 Me staff 272 Feb 26 02:11 ..
24 -rw-r--r--# 1 Me staff 10244 Mar 12 20:56 .DS_Store
0 drwxr-xr-x 5 Me staff 170 Mar 3 02:48 BonusContent
8 -rw-r--r--# 1 Me staff 48 Mar 12 20:56 Makefile
8 -rw-r--r--# 1 Me staff 322 Feb 28 00:50 ex1.c
8 -rw-r--r-- 1 v staff 184 Mar 12 19:53 ex3.c
My-MacBook-Pro:Exercises Me$ cat ex3.c
#include <stdio.h>
int main(int argc, char *argv[])
{
int age = 10;
int height = 72;
printf(" I am %d years old.\n", age);
printf(" I am %d inches tall.\n", height);
return 0;
}
My-MacBook-Pro:Exercises Me$ cat Makefile
CFLAGS=-Wall -g
all: ex3
clean:
rm -f ex3
My-MacBook-Pro:Exercises Me$ make ex3
cc -Wall -g ex3.c -o ex3
My-MacBook-Pro:Exercises Me$
My-MacBook-Pro:Exercises Me$ lldb ex3
(lldb) target create "ex3"
Current executable set to 'ex3' (x86_64).
(lldb) breakpoint set --method main
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb)
My-MacBook-Pro:Exercises Me$ ls -als
total 72
0 drwxr-xr-x 9 Me staff 306 Mar 12 20:57 .
0 drwxr-xr-x 8 Me staff 272 Feb 26 02:11 ..
24 -rw-r--r--# 1 Me staff 10244 Mar 12 20:57 .DS_Store
0 drwxr-xr-x 5 Me staff 170 Mar 3 02:48 BonusContent
8 -rw-r--r--# 1 Me staff 48 Mar 12 20:56 Makefile
8 -rw-r--r--# 1 Me staff 322 Feb 28 00:50 ex1.c
24 -rwxr-xr-x 1 Me staff 8712 Mar 12 20:57 ex3
8 -rw-r--r-- 1 Me staff 184 Mar 12 19:53 ex3.c
0 drwxr-xr-x 3 Me staff 102 Mar 12 20:57 ex3.dSYM
My-MacBook-Pro:Exercises Me$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.11.6
BuildVersion: 15G1217
My-MacBook-Pro:Exercises Me$
My-MacBook-Pro:Exercises Me$ clang --version -g
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
My-MacBook-Pro:Exercises Me$
My-MacBook-Pro:Exercises Me$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin11.3.0
My-MacBook-Pro:Exercises Me$
My-MacBook-Pro:Exercises Me$ lldb --version
lldb-360.1.70
In response to "Olaf":
LLDB Documentation
(lldb) breakpoint set --name main
(lldb) br s -n main
(lldb) b main
There is one other thread with a similar error message from 2015 on an older version of OSX, but its 'solution' does NOT work, and indeed ignores the issue by not using Make at all.
I'd like to try and avoid orthogonal or complex 'suggestions' along the lines of "Why don't you not use C, try using some other language", or "I prefer using a different debugger, so use this one" ... those won't answer the question :)

The b command and the breakpoint set command are quite different. b is a DWIM type command that tries as much as possible to emulate the gdb breakpoint parser's syntax. It eventually dispatches to break set with the appropriate breakpoint type.
breakpoint set -n foo creates a general "symbol name matching" breakpoint. So for instance, it will match a function called "foo" or an ObjC selector "foo" or a C++ method called "foo"... b foo dispatches to breakpoint set -n foo.
But sometimes you know you only want to set a breakpoint on class methods (C++ or Swift) in which case you can use the --method option to limit the search appropriately. Ditto for ObjC selectors and the --selector option.
In your case, that --name worked but --method didn't is correct behavior. Your main is a pure C function, not a class method.
BTW, the b is actually an lldb "regex command", see
(lldb) help command regex
for more details. You can see what the command is actually doing by turning on echoing the regex command resolution with:
(lldb) set set interpreter.expand-regex-aliases 1
then try some breakpoints:
(lldb) b main
breakpoint set --name 'main'
(lldb) b foo.c:11
breakpoint set --file 'foo.c' --line 11
etc...

From one person's attempt to reproduce the conditions, a valuable observation that in his installation he could get the commands to work synonymously as prescribed was helpful, and indirectly provided the solution.
I uninstalled the entire XCode module and the other supporting C development modules I had, and re-installed with fresh downloads. After that, I had the same functionality he observed.
The issue was therefore somewhere in the binary installations on my specific MacBook, perhaps due to an update not having properly applied somewhere along the way, and this was not a generic issue.

Related

"Undefined symbols for architecture x86_64:" for library using cgo on macOS Sierra

I am trying to make use of a library, https://github.com/go-steem/rpc, that makes use of some C code, which references a library.
The C library can be found here, https://github.com/bitcoin-core/secp256k1
I followed the steps to get that installed
$ ./autogen.sh
$ ./configure
$ make
$ ./tests
$ sudo make install # optional
And have this output;
$ sudo make install
Password:
CC src/libsecp256k1_la-secp256k1.lo
CCLD libsecp256k1.la
CC src/tests-tests.o
CCLD tests
CC src/exhaustive_tests-tests_exhaustive.o
CCLD exhaustive_tests
build-aux/install-sh -c -d '/usr/local/lib'
/bin/sh ./libtool --mode=install /usr/bin/install -c libsecp256k1.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libsecp256k1.0.dylib /usr/local/lib/libsecp256k1.0.dylib
libtool: install: (cd /usr/local/lib && { ln -s -f libsecp256k1.0.dylib libsecp256k1.dylib || { rm -f libsecp256k1.dylib && ln -s libsecp256k1.0.dylib libsecp256k1.dylib; }; })
libtool: install: /usr/bin/install -c .libs/libsecp256k1.lai /usr/local/lib/libsecp256k1.la
libtool: install: /usr/bin/install -c .libs/libsecp256k1.a /usr/local/lib/libsecp256k1.a
libtool: install: chmod 644 /usr/local/lib/libsecp256k1.a
libtool: install: /usr/bin/ranlib /usr/local/lib/libsecp256k1.a
build-aux/install-sh -c -d '/usr/local/include'
/usr/bin/install -c -m 644 include/secp256k1.h '/usr/local/include'
build-aux/install-sh -c -d '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 libsecp256k1.pc '/usr/local/lib/pkgconfig'
I try to run the upvote example from that Go library, go-steem/rpc/examples/upvote/ and get the following output;
$ go run main.go
# github.com/go-steem/rpc/transactions
../../transactions/signing.c:5:10: fatal error: 'secp256k1.h' file not found
Already it feels as though the wheels are falling off...
Please bear with me as I do not develop in C, so I get a bit hack-y.
After much reading, and googling I decide to copy the files from the 'include' directory where I compiled libsecp256k1 into the same directory as the error is originating from.
You can see the files are not there;
$ ls -la ../../transactions/
total 48
drwxr-xr-x 8 shaunmorrow staff 272 May 8 18:09 .
drwxr-xr-x 15 shaunmorrow staff 510 May 8 18:09 ..
-rw-r--r-- 1 shaunmorrow staff 256 Apr 27 17:53 chains.go
-rw-r--r-- 1 shaunmorrow staff 3731 May 8 18:09 signed_transaction.go
-rw-r--r-- 1 shaunmorrow staff 1849 May 8 18:09 signed_transaction_test.go
-rw-r--r-- 1 shaunmorrow staff 3075 Apr 27 17:53 signing.c
-rw-r--r-- 1 shaunmorrow staff 408 Apr 27 17:53 signing.h
-rw-r--r-- 1 shaunmorrow staff 1049 May 8 18:09 transactions.go
and after the copy;
$ ls -la ../../transactions/
total 128
drwxr-xr-x 11 shaunmorrow staff 374 Jul 18 19:08 .
drwxr-xr-x 15 shaunmorrow staff 510 May 8 18:09 ..
-rw-r--r-- 1 shaunmorrow staff 256 Apr 27 17:53 chains.go
-rw-r--r-- 1 shaunmorrow staff 27071 Jul 18 19:08 secp256k1.h
-rw-r--r-- 1 shaunmorrow staff 1014 Jul 18 19:08 secp256k1_ecdh.h
-rw-r--r-- 1 shaunmorrow staff 4700 Jul 18 19:08 secp256k1_recovery.h
-rw-r--r-- 1 shaunmorrow staff 3731 Jul 18 19:05 signed_transaction.go
-rw-r--r-- 1 shaunmorrow staff 1849 May 8 18:09 signed_transaction_test.go
-rw-r--r-- 1 shaunmorrow staff 3075 Apr 27 17:53 signing.c
-rw-r--r-- 1 shaunmorrow staff 408 Apr 27 17:53 signing.h
-rw-r--r-- 1 shaunmorrow staff 1049 May 8 18:09 transactions.go
Now I get a new error;
$ go run main.go
# github.com/go-steem/rpc/transactions
ld: library not found for -lsecp256k1
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This has me reading and googling some more,
Finally I get even more hack-y and change transactions.go;
// #cgo LDFLAGS: -lsecp256k1
// #include <stdlib.h>
// #include "signing.h"
import "C"
becomes
// #cgo LDFLAGS: -L/usr/local/lib
// #include <stdlib.h>
// #include "signing.h"
import "C"
which fails, output on that later
I also try;
// #cgo LDFLAGS: -L/usr/local/lib -I/usr/local/include
// #include <stdlib.h>
// #include "signing.h"
import "C"
and copy the .h files into the /usr/local/include directory.
None of this works and now I am stuck with an error like this
$ go run main.go
# github.com/go-steem/rpc/transactions
ld: library not found for -lsecp256k1
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ShaunsSePc-2:upvote shaunmorrow$ go run main.go
# github.com/go-steem/rpc/transactions
Undefined symbols for architecture x86_64:
"_secp256k1_context_create", referenced from:
_sign_transaction in signing.o
_verify_recoverable_signature in signing.o
"_secp256k1_context_destroy", referenced from:
_sign_transaction in signing.o
_verify_recoverable_signature in signing.o
"_secp256k1_ec_pubkey_serialize", referenced from:
_verify_recoverable_signature in signing.o
"_secp256k1_ecdsa_recover", referenced from:
_verify_recoverable_signature in signing.o
"_secp256k1_ecdsa_recoverable_signature_convert", referenced from:
_verify_recoverable_signature in signing.o
"_secp256k1_ecdsa_recoverable_signature_parse_compact", referenced from:
_verify_recoverable_signature in signing.o
"_secp256k1_ecdsa_recoverable_signature_serialize_compact", referenced from:
_sign_transaction in signing.o
"_secp256k1_ecdsa_sign_recoverable", referenced from:
_sign_transaction in signing.o
"_secp256k1_ecdsa_verify", referenced from:
_verify_recoverable_signature in signing.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
At this point I really have no idea how to continue.
As you can see I am not experienced in C at all and have no idea how to test if the library libsecp256k1 is even installed properly!
This is where I ended up, but it's highly likely I took a wrong turn early in my journey, I would appreciate any help given as I have been struggling with this for a few nights already now :(
Not sure whats needed so here some env variables
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/shaunmorrow/Work/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/86/hlqptn5101z5bcydjz05qy8m0000gn/T/go-build689438019=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
Version is go version go1.8.3 darwin/amd64 with no old versions lying around.
Thanks!
Your problem is twofold:
Improperly configured libsecp256k1 package
Your C compiler not searching /usr/local directories for installed headers/libs
Fixing the improperly libsecp256k1 configured package
Your "undefined symbols" issue when it comes to linking C libraries sometimes points to an improperly configured package (in the sense of an Autotools package or a CMake package, not a Go package). Running ./configure --help, I see there is an option named --enable-module-recovery. Judging by names like _secp256k1_ecdsa_sign_recoverable and _secp256k1_ecdsa_recover, you need to add that option when configuring, meaning instead of executing the simpler ./configure, you should execute this:
./configure --enable-module-recovery
Is the C compiler broken?
Since the secp256k1.h header file isn't found in /usr/local/include, despite the fact that the header file most definitely exists after sudo make install is finished, it means your compiler doesn't search /usr/local.
Barring any fixes in the linked question, you can work around the issue by altering the source of the Go package as needed to add/modify the CFLAGS and LDFLAGS used when dealing with import "C" statements like this:
// #cgo CFLAGS: -I/usr/local/include
// #cgo LDFLAGS: -L/usr/local/lib -lsecp256k1
// #include <secp256k1.h>
import "C"
If you have pkg-config installed, you can use that instead of setting CFLAGS and LDFLAGS manually:
Export the PKG_CONFIG_PATH environment variable with a custom set of paths. Because no prefix (i.e. directory serving as the install root) was specified, /usr/local is assumed, meaning /usr/local/include will contain headers and /usr/local/lib will contain libraries. This means you need to export PKG_CONFIG_PATH on your command line as in export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig. The default setting of PKG_CONFIG_PATH when unset includes /usr/lib/pkgconfig and /usr/share/pkgconfig in that order on Linux and are specified as a fallback for other packages that might be used, though it may not be necessary in this case. The default set of paths may differ on OS X, so consult your pkg-config man page for reference.
Use // #cgo pkg-config: libsecp256k1, and CFLAGS and LDFLAGS will be set as necessary without you needing to do anything to them. Since not all systems have pkg-config installed, relying on this is perhaps a bad idea if you want a package to remain portable. Then again, I think it'd be preferable to the mess you dealt with since pkg-config simply wouldn't be found.
Change to the upvote directory and type make to build a working upvote binary.
Additional customization
Custom prefix
If you use something other than /usr/local as your prefix (e.g. ./configure --enable-module-recovery --prefix=/opt/libsecp256k1), then you'll need to adjust some things accordingly:
// #cgo CFLAGS: -I/opt/libsecp256k1/include
// #cgo LDFLAGS: -L/opt/libsecp256k1/lib -lsecp256k1
// #include "secp256k1.h"
import "C"
// or just use pkg-config and export the PKG_CONFIG_PATH environment
// variable containing the following paths:
// /opt/libsecp256k1/lib/pkgconfig
// /opt/libsecp256k1/share/pkgconfig
// /usr/lib/pkgconfig
// /usr/share/pkgconfig
You'll also need to modify the provided Makefile in the upvote directory to set the runtime path of the binary that gets built, else libsecp256k1.0.dylib will not be found:
# If you copy and paste this, replace the spaces in front of `go build`
# with a single horizontal tab character, else `make` will fail.
#
# Note that the "ldflags" specified are for the Go linker (go tool link),
# not the system's linker (ld).
build:
go build -ldflags="-r /opt/libsecp256k1/lib"
For more information about working with cgo, check out the following resources:
"C? Go? Cgo!" introduction to cgo on The Go Blog
Cgo documentation

Why can't "go get" find $GOPATH when "go env" shows it's set correctly?

I'm attempting to get go version go1.6.4 darwin/amd64 installed on my Macbook Pro.
I can't seem to download remote packages with 'go get' despite having the $GOPATH set.
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Bryan/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
$ ls /Users/Bryan/go
total 24
drwxr-xr-x 6 Bryan staff 204 May 23 12:13 .
drwxr-xr-x+ 73 Bryan staff 2482 May 25 11:20 ..
-rw-r--r--# 1 Bryan staff 8196 May 24 15:11 .DS_Store
drwxr-xr-x 32 Bryan staff 1088 Mar 28 14:21 bin
drwxr-xr-x 3 Bryan staff 102 Mar 28 14:21 pkg
drwxr-xr-x 10 Bryan staff 340 May 25 11:18 src
Bryan#Bryans-MacBook-Pro Thu May 25 12:23:24 ~/go/src/skincarereview
$ sudo go get
Password:
package google.golang.org/appengine: cannot download, $GOPATH not set. For more details see: go help gopath
package google.golang.org/appengine/datastore: cannot download, $GOPATH not set. For more details see: go help gopath
Your $GOPATH is set in your user $PATH, but you are envoking go get using sudo which has its own $PATH different from yours.
To illustrate, try sudo go env and you will see the difference.
You probably shouldn't be using sudo go get anyway though.

Why I am getting libhdf5_hl not loaded error during executing the HDF5 example code?

I am trying to executing the c program to execute the HDF5 basic code. That is here below.
/*
* This example illustrates how to create a dataset that is a 4 x 6
* array. It is used in the HDF5 Tutorial.
*/
#include "hdf5.h"
#define FILE "dset.h5"
int main() {
hid_t file_id, dataset_id, dataspace_id; /* identifiers */
hsize_t dims[2];
herr_t status;
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create the data space for the dataset. */
dims[0] = 4;
dims[1] = 6;
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create the dataset. */
dataset_id = H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* End access to the dataset and release resources used by it. */
status = H5Dclose(dataset_id);
/* Terminate access to the data space. */
status = H5Sclose(dataspace_id);
/* Close the file. */
status = H5Fclose(file_id);
}
I am not getting any compile time error, but run time error saying it is not able load some lib. The error is pasted below -
19:36:27 macOS_ ⚡ h5cc -show myprog.c
clang -arch x86_64 myprog.c -L/Users/Ajay/anaconda/lib -lhdf5_hl -lhdf5 -arch x86_64 -lpthread -lz -ldl -lm
19:36:33 macOS_ ⚡ ./a.out
dyld: Library not loaded: #rpath/libhdf5_hl.10.dylib
Referenced from: /Users/Ajay/opensource/HDF5-Examples/./a.out
Reason: image not found
Abort trap: 6
19:36:35 macOS_ ⚡
more information on configuration -
09:11:59 macOS_ ⚡ h5cc -showconfig
SUMMARY OF THE HDF5 CONFIGURATION
=================================
General Information:
-------------------
HDF5 Version: 1.8.17
Configured on: Tue Aug 2 08:44:51 BST 2016
Configured by: ray#rays-Mac.local
Configure mode: production
Host system: i386-apple-darwin11.4.2
Uname information: Darwin rays-Mac.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64
Byte sex: little-endian
Libraries: shared
Installation point: /Users/Ajay/anaconda
Compiling Options:
------------------
Compilation Mode: production
C Compiler: /usr/bin/clang ( Apple LLVM version 4.2 )
CFLAGS: -arch x86_64
H5_CFLAGS: -O3
AM_CFLAGS:
CPPFLAGS:
H5_CPPFLAGS: -DNDEBUG -UH5_DEBUG_API
AM_CPPFLAGS:
Shared C Library: yes
Static C Library: no
Statically Linked Executables: no
LDFLAGS: -arch x86_64
H5_LDFLAGS:
AM_LDFLAGS:
Extra libraries: -lpthread -lz -ldl -lm
Archiver: ar
Ranlib: ranlib
Debugged Packages:
API Tracing: no
Languages:
----------
Fortran: no
C++: yes
C++ Compiler: /usr/bin/clang++ ( Apple LLVM version 4.2 )
C++ Flags: -arch x86_64
H5 C++ Flags: -O3
AM C++ Flags:
Shared C++ Library: yes
Static C++ Library: no
Features:
---------
Parallel HDF5: no
High Level library: yes
Threadsafety: yes
Default API Mapping: v18
With Deprecated Public Symbols: yes
I/O filters (external): deflate(zlib)
MPE: no
Direct VFD: no
dmalloc: no
Clear file buffers before write: yes
Using memory checker: no
Function Stack Tracing: no
Strict File Format Checks: no
Optimization Instrumentation: no
lib locations
09:11:56 macOS_ ⚡ ls /Users/Ajay/anaconda/lib | grep hdf5
-rwxr-xr-x 2 Ajay staff 17232 Aug 2 2016 libhdf5_hl_cpp.11.dylib
-rwxr-xr-x 2 Ajay staff 123256 Aug 2 2016 libhdf5_hl.10.dylib
-rwxr-xr-x 2 Ajay staff 445776 Aug 2 2016 libhdf5_cpp.12.dylib
-rwxr-xr-x 2 Ajay staff 2622428 Aug 2 2016 libhdf5.10.dylib
lrwxr-xr-x 1 Ajay staff 20 Mar 25 09:11 libhdf5_cpp.dylib -> libhdf5_cpp.12.dylib
lrwxr-xr-x 1 Ajay staff 16 Mar 25 09:11 libhdf5.dylib -> libhdf5.10.dylib
-rwxr-xr-x 1 Ajay staff 1087 Mar 25 09:11 libhdf5_hl_cpp.la
lrwxr-xr-x 1 Ajay staff 23 Mar 25 09:11 libhdf5_hl_cpp.dylib -> libhdf5_hl_cpp.11.dylib
-rwxr-xr-x 1 Ajay staff 988 Mar 25 09:11 libhdf5_hl.la
lrwxr-xr-x 1 Ajay staff 19 Mar 25 09:11 libhdf5_hl.dylib -> libhdf5_hl.10.dylib
-rwxr-xr-x 1 Ajay staff 993 Mar 25 09:11 libhdf5_cpp.la
-rw-r--r-- 1 Ajay staff 2243 Mar 25 09:11 libhdf5.settings
-rwxr-xr-x 1 Ajay staff 937 Mar 25 09:11 libhdf5.la
Based on the comment I can now run using
DYLD_LIBRARY_PATH=/Users/Ajay/anaconda/lib ./a.out
How to make it permanent ?
I am not on a Mac and don't use Anaconda. I'll try to guess-diagnose your problem anyway :-)
The program builds but will not execute. There is a mismatch between the libraries that are requested by the executable (libhdf5_hl.10.dylib) and the ones that are in your system.
You are using Anaconda installed hdf5. You must check what is the compiler used by Anaconda to build hdf5 and use the same.
The easiest way out is if all that is missing is the DYLD_LIBRARY_PATH path to /Users/Ajay/anaconda/lib. Try
DYLD_LIBRARY_PATH=/Users/Ajay/anaconda/lib ./a.out
For further info, please provide the output of
ls /Users/Ajay/anaconda/lib | grep hdf5
h5cc -showconfig

crash dump on ubuntu: vmlinuz or crash file not a supported file format

I am trying to analyze crash dump on my ubuntu machine using crash utility as below
$ sudo crash /boot/System.map-3.2.0-23-generic-pae /boot/vmlinuz-3.2.0-23-generic-pae _usr_sbin_ietd.0.crash
But it returns error as
crash: /boot/vmlinuz-3.2.0-23-generic-pae: not a supported file format
As per crash utility syntax I have provided arguments correctly
crash <system-map-file> <vmlinux-file> coredump
What am I doing wrong in here?
UPDATE:
vmlinuz file in boot dir appears to be bzimage compressed
$ file vmlinuz-3.2.0-23-generic-pae
vmlinuz-3.2.0-23-generic-pae: Linux kernel x86 boot executable bzImage, version 3.2.0-23-generic-pae (buildd#palmer) #36-Ubuntu SMP Tue Apr 10 , RO-rootFS, swap_dev 0x4, Normal VGA
$
As per #lurker's comments
vmlinuz is compressed and can be uncompressed using below command (from Extract vmlinux from vmlinuz or bzImage)
$ sudo dd if=vmlinuz-3.2.0-23-generic-pae skip=`grep -a -b -o -m 1 -P '\x1f\x8b\x08\x00' vmlinuz-3.2.0-23-generic-pae| cut -d: -f 1` bs=1 | zcat > /tmp/vmlinux
4998324+0 records in
4998324+0 records out
4998324 bytes (5.0 MB) copied, 201.859 s, 24.8 kB/s
gzip: stdin: decompression OK, trailing garbage ignored
Now for error
crash: /var/crash/_usr_sbin_ietd.0.crash: not a supported file format
we also need to extract core dump file from crash report using apport-unpack as below (from here)
#ubuntu:/tmp$ sudo apport-unpack
Usage: /usr/bin/apport-unpack <report> <target directory>
#ubuntu:/tmp$ sudo apport-unpack /var/crash/_usr_sbin_ietd.0.crash /var/crash/
ERROR: Destination directory exists and is not empty.
#ubuntu:/tmp$
#ubuntu:/tmp$ sudo mkdir coretest
#ubuntu:/tmp$ sudo apport-unpack /var/crash/_usr_sbin_ietd.0.crash /tmp/coretest/
#ubuntu:/tmp$ cd coretest/
#ubuntu:/tmp/coretest$
#ubuntu:/tmp/coretest$ ls
Architecture Date ExecutablePath ProblemType ProcCwd ProcMaps Signal UserGroups
CoreDump DistroRelease ExecutableTimestamp ProcCmdline ProcEnviron ProcStatus Uname
#ubuntu:/tmp/coretest$ ls -lt
total 384
-rw-r--r-- 1 root root 4 May 29 00:13 Architecture
-rw-r--r-- 1 root root 24 May 29 00:13 Date
-rw-r--r-- 1 root root 12 May 29 00:13 DistroRelease
-rw-r--r-- 1 root root 10 May 29 00:13 ExecutableTimestamp
-rw-r--r-- 1 root root 339968 May 29 00:13 CoreDump
-rw-r--r-- 1 root root 5 May 29 00:13 ProblemType
-rw-r--r-- 1 root root 66 May 29 00:13 ProcEnviron
-rw-r--r-- 1 root root 969 May 29 00:13 ProcMaps
-rw-r--r-- 1 root root 737 May 29 00:13 ProcStatus
-rw-r--r-- 1 root root 2 May 29 00:13 Signal
-rw-r--r-- 1 root root 31 May 29 00:13 Uname
-rw-r--r-- 1 root root 14 May 29 00:13 ExecutablePath
-rw-r--r-- 1 root root 14 May 29 00:13 ProcCmdline
-rw-r--r-- 1 root root 1 May 29 00:13 ProcCwd
-rw-r--r-- 1 root root 0 May 29 00:13 UserGroups
#ubuntu:/tmp/coretest$ cd CoreDump
bash: cd: CoreDump: Not a directory
#ubuntu:/tmp/coretest$ sudo crash /tmp/vmlinux /boot/System.map-3.2.0-23-generic-pae /tmp/coretest/CoreDump
crash 6.1.6
Copyright (C) 2002-2013 Red Hat, Inc.
Copyright (C) 2004, 2005, 2006, 2010 IBM Corporation
Copyright (C) 1999-2006 Hewlett-Packard Co
Copyright (C) 2005, 2006, 2011, 2012 Fujitsu Limited
Copyright (C) 2006, 2007 VA Linux Systems Japan K.K.
Copyright (C) 2005, 2011 NEC Corporation
Copyright (C) 1999, 2002, 2007 Silicon Graphics, Inc.
Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
This program is free software, covered by the GNU General Public License,
and you are welcome to change it and/or distribute copies of it under
certain conditions. Enter "help copying" to see the conditions.
This program has absolutely no warranty. Enter "help warranty" for details.
GNU gdb (GDB) 7.3.1
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
crash: /tmp/vmlinux: no debugging data available
#ubuntu:/tmp/coretest$
For "No debugging data available", need some debuginfo packages (programname-dbg or progname-dbgsym) installed as per this link and this one
Steps for downloading debuginfo packages for kernel are mentioned in question https://askubuntu.com/questions/197016/how-to-install-a-package-that-contains-ubuntu-kernel-debug-symbols
However, step of adding GPG key(as below) is crucial for the download to work
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ECDCAD72428D7C01
You should receive message as
public key "Ubuntu Debug Symbol Archive Automatic Signing Key
" imported
and not "not changed" status. If it says "not changed" in this step then You wont be able to download debuginfo package.
In that case try importing GPG key using http 80 port as(here)
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
vmlinuz is a compressed file, but crash requires an uncompressed file vmlinux, which is compiled with -g option.
Make sure your kernel is compiled with -g option, and then you can get an uncompressed vmlinux file from compressed vmlinuz, using the method as follows:
1. od -t x1 -A d vmlinuz | grep "1f 8b 08"
e.g. you get an output:
0018352 ac fe ff ff 1f 8b 08 00 00 00 00 00 02 03 ec fd
2. Compute the offset to "1f 8b 08": 0018352 + 4 = 0018356.
3. Use dd to uncompress your vmlinuz:
dd if=vmlinuz bs=1 skip=18356 | zcat > vmlinux
Now you get the uncompressed kernel file vmlinux. Congratulations!

How can I use a GMP library I just built from source?

I've got a tiny C program with the following header:
#include <gmp.h>
I compile it doing:
gcc test.c -o test.o -L/gmp_install/lib -lgmp
And then I can run it fine. But it is using the "stock" GMP library on my system.
Now I'd like to compile it using another version of the GMP lib, which I installed locally and I can't make it work.
The new library is apparently installed in /usr/local/lib:
... $ ls -l /usr/local/lib
-rw-r--r-- 1 root staff 1276320 Jun 15 02:22 libgmp.a
-rwxr-xr-x 1 root staff 914 Jun 15 02:22 libgmp.la
lrwxrwxrwx 1 root staff 16 Jun 15 02:22 libgmp.so -> libgmp.so.10.2.0
lrwxrwxrwx 1 root staff 16 Jun 15 02:22 libgmp.so.10 -> libgmp.so.10.2.0
-rwxr-xr-x 1 root staff 528715 Jun 15 02:22 libgmp.so.10.2.0
But no matter what I try, it's apparently the old library that is used.
Even using:
gcc perf.c -o perf.o -O3 -L/ -lgmp
But it's using the GMP version in /usr/lib/x86_64-linux-gnu/.
What is the correct way to use the GMP version in /usr/local/bin, knowing I'd like to keep the old version too?
Also, once the executable is created, is there an easy way to see which library it shall use at runtime? (can I create the executable with one version of GMP and then execute it with another version of GMP, knowing the lib is dynamically linked?)
Do two things:
Use -L/usr/local/lib flag while compiling
Set LD_LIBRARY_PATH variable while running your program to have /usr/local/lib. Thus, if you are using a bash shell, you will have to do something like
$ export LD_LIBRARY_PATH=/usr/local/lib
$ ./your_program
to use the /usr/local/lib version at runtime. Also, in order to see which one it will use at runtime, you can always do ldd <your binary name> which will print out all the dynamic dependencies.

Resources