Created programs compiled with gcc using root,now I am into problems about not having execution permission & chmod gives .o file with EXE format error - c

I have simple code files and Makefile the generates some executable files. Now I am having problem with running it. First that the output of gcc is not giving me .o file with execution permission. Which is surprising, at the bottom is my makefile I ran into these issues below.
With ls -lh command it says I only have maximum read and write permission to a writeshmem.o. same for all files in the directory. Even though I don't remember setting any system wide permission for outputting .o file without execution permission from gcc. And I DO NOT REMEMBER REVOKING ROOT USER PERMISSION.
root#fawad:/home/fawad/Desktop/Shared# ls -lh
total 44K
-rw-r--r-- 1 root root 263 Sep 6 14:07 Makefile
-rw-r--r-- 1 root root 359 Sep 6 14:10 destroy_shmem.c
-rw-r--r-- 1 root root 3.9K Sep 6 14:10 destroy_shmem.o
-rw-r--r-- 1 root root 381 Sep 6 13:40 readshmem.c
-rw-r--r-- 1 root root 4.1K Sep 6 14:14 readshmem.o
-rw-r--r-- 1 root root 1014 Sep 6 11:58 shared_memory.c
-rw-r--r-- 1 root root 267 Sep 6 14:09 shared_memory.h
-rw-r--r-- 1 root root 490 Sep 6 13:30 writeshmem.c
-rw-r--r-- 1 root root 4.2K Sep 6 14:14 writeshmem.o
As u can see there is no execution x
After above when I gave permission with
root#fawad:/home/fawad/Desktop/Shared# chmod +rwx writeshmem.o
I got this error
root#fawad:/home/fawad/Desktop/Shared# ./writeshmem.o
bash: ./writeshmem.o: cannot execute binary file: Exec format error
What that above error even means. It make no sense to me how giving permission to a file messed up with the EXecution format of the file. Someone can please explain why it matters for a file to cause this error. I only change the permission.
Makefile
CC=gcc
CFLAGS=-g -Wall
OBJS=shared_memory.o
EXE=writeshmem.o readshmem.o destroy_shmem.o
all: $(EXE)
%.o: %.o $(OBJS)
$(CC) $(CFLAGS) $< $(OBJS) -o $#
%.o: %.c %.h
$(CC) $(CFLAGS) -c $< -o $#
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $#
clean:
rm .o $(EXE)
Update
after reading comment(You should remove the .o from the executable names) by kaylum I removed .o from executables in makefile But I still get error
root#fawad:/home/fawad/Desktop/Shared# ./writeshmem
bash: ./writeshmem: Permission denied
and same output from ls -lh
-rw-r--r-- 1 root root 251 Sep 6 14:59 Makefile
-rw-r--r-- 1 root root 3.9K Sep 6 15:00 destroy_shmem
-rw-r--r-- 1 root root 359 Sep 6 14:10 destroy_shmem.c
-rw-r--r-- 1 root root 4.1K Sep 6 15:00 readshmem
-rw-r--r-- 1 root root 381 Sep 6 13:40 readshmem.c
-rw-r--r-- 1 root root 1014 Sep 6 11:58 shared_memory.c
-rw-r--r-- 1 root root 267 Sep 6 14:09 shared_memory.h
-rw-r--r-- 1 root root 4.2K Sep 6 15:00 writeshmem
-rw-r--r-- 1 root root 490 Sep 6 13:30 writeshmem.c
everything including writeshmem is still with only rw permission and without x

Related

Shared object creation: dangling symlink using make

I am trying to create a shared library using gcc and make. I have the following section in the Makefile to compile the shared library object:
# The library build step.
lib : $(DHLLOBJS)
$(CC) $(XCFLAGS) $(SCFLAGS)$(SLIB).1 $(INCFLAGS) -o $(LIB_DIR)/$(SLIB).1.0 \
$(DLOPATHS) $(LNKFLAGS)
ln -sf $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB).1
ln -sf $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB)
The above doesn't throw any compilation errors or file system errors but the symlinks are described as dangling as shown by a chmod command:
$ sudo chmod 0755 ../lib/*
chmod: cannot operate on dangling symlink '../lib/libdhlim.so'
chmod: cannot operate on dangling symlink '../lib/libdhlim.so.1'
and the ls command output below shows the lines 5 and 6 in red:
$ ls -la lib/
total 29
drwxrwxrwx 1 root root 376 Jul 5 21:13 .
drwxrwxrwx 1 root root 4096 Jul 5 21:13 ..
lrwxrwxrwx 1 root root 21 Jul 5 21:13 libdhlim.so -> ./lib/libdhlim.so.1.0
lrwxrwxrwx 1 root root 21 Jul 5 21:13 libdhlim.so.1 -> ./lib/libdhlim.so.1.0
-rwxrwxrwx 1 root root 23792 Jul 5 21:13 libdhlim.so.1.0
When I run the same set of commands manually, they work fine. Is there something I am doing wrong here?
The problem is that you use relative paths but don't create the links with the ln option -r.
Try these as the last two lines:
ln -sfr $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB).1
ln -sfr $(LIB_DIR)/$(SLIB).1.0 $(LIB_DIR)/$(SLIB)
-r, --relative
with -s, create links relative to link location

How to create an executable that links to a static library using a Makefile?

I'm new to C, and Makefiles are giving me a hard time. Within the Makefile, I want to make an executable that links to a static library. My understanding is that to generate an executable from test.c located in src/project the command would be gcc src/project/test.c -o test, and this executable would be named test. If I wanted to have the executable also link with a static library, lib.a how would I do that?
First of all, lib.a is not a canonically "valid" static library filename, library filenames should start with lib and continue with the actual name of the library, e.g. libsomething.a. You would then link such library with -lsomething, assuming it is in the appropriate system directories. If not, you can add -Lpath/to/directory to make the linker also look into path/to/directory for libsomething.a. See also: Order in which library directories are searched and linked. Alternatively, in case of a static library you could also add the library directly to the GCC command line: gcc prog.c libsomething.a.
In a very basic Makefile I would do something like this:
test: src/project/test.c path/to/libsomething.a
gcc $^ -o $#
If I wanted to have the executable also link with a static library, lib.a how would I do that?
Short answer is: just include the library in the gcc command using
gcc src/project/test.c -o test libstuff.a
Or use
gcc src/project/test.c -o test -lstuff -Llibfolder
-L adds the libfolder to the list of folders where search for libraries are done. There is a folder search sequence for libraries similar to what happens with #include processing.
back to make
I will show a minimal example of how to build and use an static library in C and manage its use via a very short makefile, under Linux Ubuntu 20.
This is minimal and just for demonstration purposes. There are better ways to write this but I hope that writing this way will make easier for you to follow the logic.
Note: ar is the archiver in Linux, just like LIB in Windows. The program that manages creation of libraries.
Example
Take a folder with these 4 files
Makefile myLib.c myLib.h testing.c
We want to build a library libmyLib.a from myLib.c and use it in testing
The C sources
For the library:
// myLib.h
int twice(int);
// myLib.c
#include <stdio.h>
int twice(int value) { return value + value; }
The test program
// testing.c
#include <stdio.h>
#include "myLib.h"
int main(void)
{ int x = 42;
printf("x = %d, twice(%d) = %d\n", x, x, twice(x) );
return 0;
}
test output
testing just calls twice(42) and outputs 84
x = 42, twice(42) = 84
using the makefile
We want to type make and have libmyLib.a built, testing.c compiled and testing generated.
Something like (with make output suppressed by now):
so_user#DSK-2009:~/projects/so0802$ ls -ltr
total 32
-rw-r--r-- 1 so_user so_user 266 Aug 2 17:46 Makefile
-rw-r--r-- 1 so_user so_user 26 Aug 2 18:23 myLib.h
-rw-r--r-- 1 so_user so_user 155 Aug 2 18:23 testing.c
-rw-r--r-- 1 so_user so_user 79 Aug 2 18:23 myLib.c
so_user#DSK-2009:~/projects/so0802$ make
// supressed output //
so_user#DSK-2009:~/projects/so0802$ ls -ltr
total 44
-rw-r--r-- 1 so_user so_user 266 Aug 2 17:46 Makefile
-rw-r--r-- 1 so_user so_user 26 Aug 2 18:23 myLib.h
-rw-r--r-- 1 so_user so_user 155 Aug 2 18:23 testing.c
-rw-r--r-- 1 so_user so_user 79 Aug 2 18:23 myLib.c
-rw-r--r-- 1 so_user so_user 1792 Aug 2 18:42 testing.o
-rw-r--r-- 1 so_user so_user 1368 Aug 2 18:42 myLib.o
-rw-r--r-- 1 so_user so_user 1510 Aug 2 18:42 libmyLib.a
-rwxr-xr-x 1 so_user so_user 16760 Aug 2 18:42 testing
so_user#DSK-2009:~/projects/so0802$ ./testing
x = 42, twice(42) = 84
so_user#DSK-2009:~/projects/so0802$
make is an absurdly clever program that takes into account the last modification time of the files to, yes, make things up to date. make is based on so called makefiles, whose name defaults to Makefile. In the makefile things to be updated are called targets.
A makefile, even for a short project, can be a complex thing. But is always easier than not using one.
what would a make run do?
you can present the so called targets to make. If you just type make the program will search for a file named Makefile and inside the file for a target named all.
The first command below only updates the library, while the second will try the target all
make libMylib.a
make
make -n
You can always try -n and make will list what the program will do to update the targets.
Following the example above...
so_user#DSK-2009:~/projects/so0802$ make -n
make: Nothing to be done for 'all'.
so_user#DSK-2009:~/projects/so0802$
As the targets are all updated. Now suppose testing.c is changed:
so_user#DSK-2009:~/projects/so0802$ touch testing.c
so_user#DSK-2009:~/projects/so0802$ ls -ltr
total 44
-rw-r--r-- 1 so_user so_user 266 Aug 2 17:46 Makefile
-rw-r--r-- 1 so_user so_user 26 Aug 2 18:23 myLib.h
-rw-r--r-- 1 so_user so_user 79 Aug 2 18:23 myLib.c
-rw-r--r-- 1 so_user so_user 1792 Aug 2 18:42 testing.o
-rw-r--r-- 1 so_user so_user 1368 Aug 2 18:42 myLib.o
-rw-r--r-- 1 so_user so_user 1510 Aug 2 18:42 libmyLib.a
-rwxr-xr-x 1 so_user so_user 16760 Aug 2 18:42 testing
-rw-r--r-- 1 so_user so_user 155 Aug 2 18:57 testing.c
so_user#DSK-2009:~/projects/so0802$ make -n
gcc -c -Wall testing.c
gcc -o testing testing.o libmyLib.a
so_user#DSK-2009:~/projects/so0802$
And you see that, as testing.c is newer, but as the library has not changed, we need to compile the program and link it with the library:
-rw-r--r-- 1 toninho toninho 266 Aug 2 17:46 Makefile
-rw-r--r-- 1 toninho toninho 26 Aug 2 18:23 myLib.h
-rw-r--r-- 1 toninho toninho 79 Aug 2 18:23 myLib.c
-rw-r--r-- 1 toninho toninho 1368 Aug 2 18:42 myLib.o
-rw-r--r-- 1 toninho toninho 1510 Aug 2 18:42 libmyLib.a
-rw-r--r-- 1 toninho toninho 155 Aug 2 18:57 testing.c
-rw-r--r-- 1 toninho toninho 1792 Aug 2 19:00 testing.o
-rwxr-xr-x 1 toninho toninho 16760 Aug 2 19:00 testing
But now we change myLib.c and try make -n:
so_user#DSK-2009:~/projects/so0802$ touch myLib.c
so_user#DSK-2009:~/projects/so0802$ make -n
gcc -c -Wall testing.c
gcc -c -Wall myLib.c
ar rcs libmyLib.a myLib.o
gcc -o testing testing.o libmyLib.a
so_user#DSK-2009:~/projects/so0802$
since the library changed, the header file could have also changed so we need to compile testing.c also. And call ar to rebuild the library, before generating a new testing executable.
The makefile used here
all: testing
clean:
rm *.o
rm *.a
rm testing
testing: testing.o libmyLib.a
gcc -o testing testing.o libmyLib.a
testing.o: testing.c myLib.c myLib.h
gcc -c -Wall testing.c
myLib.o: myLib.c myLib.h
gcc -c -Wall myLib.c
libmyLib.a: myLib.o
ar rcs libmyLib.a myLib.o
I hope it is a bit clear how things go with make. Fell free to ask back about this.
the things before : are the targets
the clean target is usual, and you see here it just removes things
the things listed after a target are called dependencies, and it makes sense: if any of the dependencies are newer than the target the commands below the line of dependencies are run.
make is deeply recursive in the search of targets to update

How to enable pg_audit extention in postgresql 11

I have tried lot by searching goggle to solve it.but unable to compile as per documentation in below GitHub.
Pg_Audit Extention
below is the env. for my postgres user.
export PGHOME=/var/lib/pgsql/
export PGDATA=/var/lib/pgsql/11/data/
export PGDATABASE=postgres
export PGUSER=postgres
export PGPORT=xxxx
export PGLOCALEDIR=/usr/pgsql-11/share/
Following below STEPS. I am using to make install/compile.
-bash-4.2$ pwd
/var/lib/pgsql
-bash-4.2$ cd pgaudit-REL_11_STABLE/
-bash-4.2$ pwd
/var/lib/pgsql/pgaudit-REL_11_STABLE
-bash-4.2$ ll
total 528
drwx------. 2 postgres postgres 25 May 23 2019 expected
-rw-------. 1 postgres postgres 171 May 23 2019 LICENSE
-rw-------. 1 postgres postgres 548 May 23 2019 Makefile
-rw-------. 1 postgres postgres 175 May 23 2019 pgaudit--1.3--1.3.1.sql
-rw-------. 1 postgres postgres 615 May 23 2019 pgaudit--1.3.1.sql
-rw-------. 1 postgres postgres 63517 May 23 2019 pgaudit.c
-rw-------. 1 postgres postgres 35 May 23 2019 pgaudit.conf
-rw-------. 1 postgres postgres 145 May 23 2019 pgaudit.control
-rw-------. 1 postgres postgres 266312 Feb 9 11:48 pgaudit.o
-rwx------. 1 postgres postgres 157624 Feb 9 11:48 pgaudit.so
-rw-------. 1 postgres postgres 17312 May 23 2019 README.md
drwx------. 2 postgres postgres 25 May 23 2019 sql
drwx------. 2 postgres postgres 25 May 23 2019 test
-bash-4.2$
-bash-4.2$ make check USE_PGXS=1
"make check" is not supported.
Do "make install", then "make installcheck" instead.
-bash-4.2$ make install
/opt/rh/llvm-toolset-7/root/usr/bin/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -O2 -I. -I./ -I/usr/pgsql-11/include/server -I/usr/pgsql-11/in
clude/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include -flto=thin -emit-llvm -c -o pgaudit.bc pgaudit.c
make: /opt/rh/llvm-toolset-7/root/usr/bin/clang: Command not found
make: *** [pgaudit.bc] Error 127
-bash-4.2$
I also copied pg_audit.so
scp -r /var/lib/pgsql/pgaudit-REL_11_STABLE/pgaudit.so /usr/pgsql-11/share/contrib/
cd /usr/pgsql-11/share/contrib/
/usr/pgsql-11/share/contrib
-bash-4.2$ ll
total 176
-rwx------. 1 root root 157624 Feb 10 07:43 pgaudit.so
-rw-------. 1 root root 14875 Feb 10 08:10 pgaudit.sql
-rw-r--r--. 1 root root 1644 Aug 7 2019 sepgsql.sql
-bash-4.2$ pwd
/usr/pgsql-11/share/contrib
also when i use below command getting below error.
-bash-4.2$ make install PGUSER=postgres USE_PGXS=1 PATH=/usr/pgsql-11/bin:{PATH}
/opt/rh/llvm-toolset-7/root/usr/bin/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -O2 -I. -I./ -I/usr/pgsql-11/include/server -I/usr/pgsql-11/in
clude/internal -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include -flto=thin -emit-llvm -c -o pgaudit.bc pgaudit.c
make: /opt/rh/llvm-toolset-7/root/usr/bin/clang: Command not found
make: *** [pgaudit.bc] Error 127
I am missing something related to copying or setting env. please help me.
Edit: I go through suggested by Laurenz Albe in below answer. now getting below error.
[root#ip- pgaudit-REL_11_STABLE]# /usr/bin/make install PGUSER=postgres USE_PGXS=1 with_llvm=no make -e PATH=/usr/pgsql-11/bin:{PATH}
/usr/bin/mkdir -p '/usr/lib64/pgsql'
/usr/bin/mkdir -p '/usr/share/pgsql/extension'
/usr/bin/mkdir -p '/usr/share/pgsql/extension'
/bin/sh /usr/lib64/pgsql/pgxs/src/makefiles/../../config/install-sh -c -m 755 pgaudit.so '/usr/lib64/pgsql/pgaudit.so'
/usr/lib64/pgsql/pgxs/src/makefiles/../../config/install-sh: line 75: uname: command not found
/usr/lib64/pgsql/pgxs/src/makefiles/../../config/install-sh: line 326: sed: command not found
/usr/lib64/pgsql/pgxs/src/makefiles/../../config/install-sh: line 461: exec: cp: not found
/usr/lib64/pgsql/pgxs/src/makefiles/../../config/install-sh: line 1: rm: command not found
make: *** [install-lib-shared] Error 1
i have checked in /usr/bin all required utilities are available.
[root#ip- pgaudit-REL_11_STABLE]# ls -lrth /usr/bin/ | grep uname
lrwxrwxrwx. 1 root root 7 Jun 18 2019 uname26 -> setarch
-rwxr-xr-x. 1 root root 29K Jan 23 19:07 uname
[root#ip pgaudit-REL_11_STABLE]# ls -lrth /usr/bin/ | grep sed
-rwxr-xr-x. 1 root root 75K Aug 1 2018 sed
-rwxr-xr-x. 2 root root 53K Feb 19 2019 psed
[root#ip pgaudit-REL_11_STABLE]# ls -lrth /usr/bin/ | grep exec
-rwxr-xr-x. 1 root root 16K Aug 2 2018 msgexec
[root#ip pgaudit-REL_11_STABLE]# ls -lrth /usr/bin/ | grep rm
-rwxr-xr-x. 1 root root 41K Jan 23 19:07 rmdir
Now getting below error. I am really not able to understand what error want to say. please help.
[root# pgaudit-REL_11_STABLE]# make install PGUSER=postgres USE_PGXS=1 PATH=/usr/pgsql-11/bin:$PATH with_llvm=no make -e
/usr/bin/mkdir -p '/usr/lib64/pgsql'
/usr/bin/mkdir -p '/usr/share/pgsql/extension'
/usr/bin/mkdir -p '/usr/share/pgsql/extension'
/bin/sh /usr/lib64/pgsql/pgxs/src/makefiles/../../config/install-sh -c -m 755 pgaudit.so '/usr/lib64/pgsql/pgaudit.so'
/bin/sh /usr/lib64/pgsql/pgxs/src/makefiles/../../config/install-sh -c -m 644 ./pgaudit.control '/usr/share/pgsql/extension/'
/bin/sh /usr/lib64/pgsql/pgxs/src/makefiles/../../config/install-sh -c -m 644 ./pgaudit--1.3.1.sql ./pgaudit--1.3--1.3.1.sql '/usr/share/pgsql/extension/'
make: *** No rule to make target `make'. Stop.
[root# pgaudit-REL_11_STABLE]#
You should install clang so that PGXS can build the byte code.
If you don't need JIT, a workaround is to build with
with_llvm=no make -e
To add /usr/pgsql-11/bin to the PATH, run
PATH=/usr/pgsql-11/bin:$PATH with_llvm=no make -e

Why does C library link order only matter on some systems?

My group developing a program which uses the JasPer library which depends on a JPEG library. My co-worker created a Makefile which listed the -ljpeg before -ljasper in the build rule. This worked fine on my co-worker's computer but would not build on mine:
$ make
cc -DDEBUG compress_image_test.c -o compress_image_test -Wall -ljpeg -ljasper -lm -lcheck
/usr/local/lib/libjasper.a(jpg_dec.o): In function `jpg_decode':
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:158: undefined reference to `jpeg_std_error'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:159: undefined reference to `jpeg_CreateDecompress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:162: undefined reference to `jpeg_stdio_src'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:165: undefined reference to `jpeg_read_header'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:168: undefined reference to `jpeg_start_decompress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:190: undefined reference to `jpeg_read_scanlines'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:197: undefined reference to `jpeg_finish_decompress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_dec.c:200: undefined reference to `jpeg_destroy_decompress'
/usr/local/lib/libjasper.a(jpg_enc.o): In function `jpg_encode':
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:284: undefined reference to `jpeg_std_error'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:285: undefined reference to `jpeg_CreateCompress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:288: undefined reference to `jpeg_stdio_dest'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:294: undefined reference to `jpeg_set_defaults'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:310: undefined reference to `jpeg_set_quality'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:314: undefined reference to `jpeg_default_colorspace'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:317: undefined reference to `jpeg_start_compress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:324: undefined reference to `jpeg_write_scanlines'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:329: undefined reference to `jpeg_finish_compress'
/cots/jasper-1.900.1/src/libjasper/jpg/jpg_enc.c:330: undefined reference to `jpeg_destroy_compress'
collect2: ld returned 1 exit status
make: *** [compress_image_test] Error 1
Both machines are running Ubuntu 12.04. The JasPer and JPEG libraries were built from source, not obtained through apt-get.
After reading another stack exchange post, lib dependencies and their order, I tried updating the makefile to swap the order of -ljpeg to after -ljasper. This worked.
So my question is, was the original order ok on another machine, which is basically equivalent to mine, but it did not work on my machine?
May 5th Update:
These are the relevant library files that I can find on my computer:
/usr/lib/i386-linux-gnu:
lrwxrwxrwx 1 root root 18 Jun 21 2012 libjasper.so.1 -> libjasper.so.1.0.0
-rw-r--r-- 1 root root 317148 Jan 11 2012 libjasper.so.1.0.0
lrwxrwxrwx 1 root root 16 Nov 22 07:42 libjpeg.so.8 -> libjpeg.so.8.0.2
-rw-r--r-- 1 root root 284436 Nov 22 07:42 libjpeg.so.8.0.2
/usr/local/lib:
-rw-r--r-- 1 root root 1361856 May 2 09:14 libjasper.a
-rwxr-xr-x 1 root root 757 May 2 09:14 libjasper.la
-rw-r--r-- 1 root root 1461672 May 2 09:15 libjpeg.a
-rwxr-xr-x 1 root root 918 May 2 09:15 libjpeg.la
lrwxrwxrwx 1 root root 16 May 2 09:15 libjpeg.so -> libjpeg.so.9.1.0
lrwxrwxrwx 1 root root 16 May 2 09:15 libjpeg.so.9 -> libjpeg.so.9.1.0
-rwxr-xr-x 1 root root 955739 May 2 09:15 libjpeg.so.9.1.0
And the same files as they exist on my co-workers computer:
/usr/lib/i386-linux-gnu:
lrwxrwxrwx 1 root root 18 Oct 29 2013 libjasper.so.1 -> libjasper.so.1.0.0
-rw-r--r-- 1 root root 317148 Jan 11 2012 libjasper.so.1.0.0
lrwxrwxrwx 1 root root 16 Nov 22 07:42 libjpeg.so.8 -> libjpeg.so.8.0.2
-rw-r--r-- 1 root root 284436 Nov 22 07:42 libjpeg.so.8.0.2
/usr/local/lib:
-rw-r--r-- 1 root root 1320124 Apr 24 16:01 libjasper.a
-rwxr-xr-x 1 root root 750 Apr 24 16:01 libjasper.la
-rw-r--r-- 1 root root 1462456 Apr 24 16:06 libjpeg.a
-rwxr-xr-x 1 root root 918 Apr 24 16:06 libjpeg.la
lrwxrwxrwx 1 root root 16 Apr 24 16:06 libjpeg.so -> libjpeg.so.9.1.0
lrwxrwxrwx 1 root root 16 Apr 24 16:06 libjpeg.so.9 -> libjpeg.so.9.1.0
-rwxr-xr-x 1 root root 955351 Apr 24 16:06 libjpeg.so.9.1.0
As far as I can see, all of the same files and links exist on the two systems.
You are probably linking against a static library.
With dynamic libraries, the whole library is included in the link, which will make all of its symbols available to objects mentioned later, while for a static library, only those archive members that satisfy currently undefined symbols are linked, and the rest of the library ignored.
There is two possibilities for dynamic libraries:
If you set LD_LIBRARY_PATH to include path that in it libjpeg.so could be found, then ld will search in these paths for libjpeg.so automatically when it find out that libjasper.so needs it.
That libjasper.so may be built with a -rpath ld option. In this case, ld also will search in that path for dependent libraries automatically.
You can find out whether there is a rpath in libjasper.so by readelf -d /path/to/libjasper.so.

Run the libspotify examples

I am trying to run the spotify examples. I have sucecsfully compiled them but I cannot run anything. When i.e. do ./jukebox.o it just says "cannot execute binary file". How do I run the examples?
This is what I got when i did make:
libspotify/examples$ make LIBSPOTIFY_PATH=../../../..
for a in jukebox spshell localfiles; do make -C $a LIBSPOTIFY_PATH="/home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release" all; done
make[1]: Entering directory /home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/share/doc/libspotify/examples/jukebox'
cc -I/usr/include/alsa -I/home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/include -Wall -Wl,-rpath,/home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/lib -L/home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/lib jukebox.o appkey.o alsa-audio.o audio.o -o jukebox -lasound -lspotify
/usr/bin/ld: alsa-audio.o: undefined reference to symbol 'pthread_create##GLIBC_2.2.5'
/lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[1]: *** [jukebox] Error 1
make[1]: Leaving directory/home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/share/doc/libspotify/examples/jukebox'
make[1]: Entering directory /home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/share/doc/libspotify/examples/spshell'
cc -I/home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/include -Wall -Wl,-rpath,/home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/lib -L/home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/lib spshell.o spshell_posix.o appkey.o cmd.o browse.o search.o toplist.o inbox.o star.o playlist.o test.o -lreadline -lspotify -o spshell
/usr/bin/ld: spshell_posix.o: undefined reference to symbol 'pthread_create##GLIBC_2.2.5'
/lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[1]: *** [spshell] Error 1
make[1]: Leaving directory/home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/share/doc/libspotify/examples/spshell'
make[1]: Entering directory /home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/share/doc/libspotify/examples/localfiles'
make[1]: Leaving directory/home/alexander/slask/libspotify-12.1.51-Linux-x86_64-release/share/doc/libspotify/examples/localfiles'
I had a similar problem on 64-Bit Ubuntu. Edit the LDLIBS line in examples/common.mk to read as follows
LDLIBS += -lspotify -lpthread -ldl
You have to make the file executable.
Try chmod u+x jukebox.o and if that doesn't work, you should try compiling it like gcc jukebox.c -o jukebox
On Linux, after you've successfully run the makefile, your share/doc/libspotify/examples/jukebox directory should look like this:
weeble#mylaptop:~/prj/libspotify/libspotify-12.1.51-Linux-i686-release/share/doc/libspotify/examples$ ls -l jukebox/
total 140
-rw-r--r-- 1 weeble weeble 5588 Jun 13 2012 alsa-audio.c
-rw-r--r-- 1 weeble weeble 5392 Feb 26 09:25 alsa-audio.o
-rw-r--r-- 1 weeble weeble 856 Feb 26 09:26 appkey.o
-rw-r--r-- 1 weeble weeble 1840 Jun 13 2012 audio.c
-rw-r--r-- 1 weeble weeble 1828 Jun 13 2012 audio.h
-rw-r--r-- 1 weeble weeble 1400 Feb 26 09:25 audio.o
-rw-r--r-- 1 weeble weeble 1718 Jun 13 2012 dummy-audio.c
-rwxr-xr-x 1 weeble weeble 21865 Feb 26 09:26 jukebox
-rw-r--r-- 1 weeble weeble 15156 Jun 13 2012 jukebox.c
-rw-r--r-- 1 weeble weeble 9116 Feb 26 09:19 jukebox.o
-rw-r--r-- 1 weeble weeble 1051 Jun 13 2012 Makefile
-rw-r--r-- 1 weeble weeble 4469 Jun 13 2012 openal-audio.c
drwxr-xr-x 3 weeble weeble 4096 Jun 13 2012 osx
-rw-r--r-- 1 weeble weeble 3378 Jun 13 2012 osx-audio.c
-rw-r--r-- 1 weeble weeble 8860 Jun 13 2012 playtrack.c
-rw-r--r-- 1 weeble weeble 18990 Jun 13 2012 queue.h
The executable file is the one called "jukebox". So run "./jukebox/jukebox". If that file isn't there, perhaps the build process failed. Were there any messages or warnings when you ran "make"?

Resources