I am trying to statically link and use a library that I installed in my system, but even when at compile/link time I do not get errors. At runtime I get them.
Getting the library
I downloaded and installed libpfm4. I ran make sudo make install:
And got this:
installing in /usr/local
make[1]: Entering directory '/home/username/libpfm4/lib'
building: libpfm.a libpfm.so.4.11.1
mkdir -p /usr/local/lib
install -m 644 libpfm.a /usr/local/lib
install libpfm.so.4.11.1 /usr/local/lib
cd /usr/local/lib; ln -sf libpfm.so.4.11.1 libpfm.so.4
cd /usr/local/lib; ln -sf libpfm.so.4.11.1 libpfm.so
ldconfig
make[1]: Leaving directory '/home/username/libpfm4/lib'
make[1]: Entering directory '/home/username/libpfm4/tests'
make[1]: Nothing to be done for 'install'.
make[1]: Leaving directory '/home/username/libpfm4/tests'
make[1]: Entering directory '/home/username/libpfm4/examples'
make[1]: Nothing to be done for 'install'.
make[1]: Leaving directory '/home/username/libpfm4/examples'
make[1]: Entering directory '/home/username/libpfm4/perf_examples'
make[1]: Nothing to be done for 'install'.
make[1]: Leaving directory '/home/username/libpfm4/perf_examples'
make[1]: Entering directory '/home/username/libpfm4/include'
mkdir -p /usr/local/include/perfmon
install -m 644 perfmon/pfmlib.h perfmon/perf_event.h perfmon/pfmlib_perf_event.h /usr/local/include/perfmon
make[1]: Leaving directory '/home/username/libpfm4/include'
make[1]: Entering directory '/home/username/libpfm4/docs'
mkdir -p /usr/local/share/man/man3
( cd man3; install -m 644 libpfm.3 pfm_find_event.3 pfm_get_event_attr_info.3 pfm_get_event_info.3 pfm_get_event_encoding.3 pfm_get_event_next.3 pfm_get_pmu_info.3 pfm_get_os_event_encoding.3 pfm_get_version.3 pfm_initialize.3 pfm_terminate.3 pfm_strerror.3 libpfm_intel_core.3 libpfm_intel_x86_arch.3 libpfm_amd64.3 libpfm_amd64_k7.3 libpfm_amd64_k8.3 libpfm_amd64_fam10h.3 libpfm_amd64_fam15h.3 libpfm_amd64_fam16h.3 libpfm_amd64_fam17h.3 libpfm_amd64_fam17h_zen2.3 libpfm_amd64_fam19h_zen3.3 libpfm_amd64_fam19h_zen3_l3.3 libpfm_intel_atom.3 libpfm_intel_nhm.3 libpfm_intel_nhm_unc.3 libpfm_intel_wsm.3 libpfm_intel_wsm_unc.3 libpfm_intel_snb.3 libpfm_intel_snb_unc.3 libpfm_intel_ivb.3 libpfm_intel_ivb_unc.3 libpfm_intel_hsw.3 libpfm_intel_bdw.3 libpfm_intel_rapl.3 libpfm_intel_slm.3 libpfm_intel_tmt.3 libpfm_intel_skl.3 libpfm_intel_icl.3 libpfm_intel_glm.3 libpfm_intel_knl.3 libpfm_intel_knm.3 libpfm_intel_snbep_unc_cbo.3 libpfm_intel_snbep_unc_ha.3 libpfm_intel_snbep_unc_imc.3 libpfm_intel_snbep_unc_pcu.3 libpfm_intel_snbep_unc_qpi.3 libpfm_intel_snbep_unc_ubo.3 libpfm_intel_snbep_unc_r2pcie.3 libpfm_intel_snbep_unc_r3qpi.3 libpfm_intel_ivbep_unc_cbo.3 libpfm_intel_ivbep_unc_ha.3 libpfm_intel_ivbep_unc_imc.3 libpfm_intel_ivbep_unc_pcu.3 libpfm_intel_ivbep_unc_qpi.3 libpfm_intel_ivbep_unc_ubo.3 libpfm_intel_ivbep_unc_r2pcie.3 libpfm_intel_ivbep_unc_r3qpi.3 libpfm_intel_ivbep_unc_irp.3 libpfm_intel_knc.3 libpfm_intel_hswep_unc_cbo.3 libpfm_intel_hswep_unc_ha.3 libpfm_intel_hswep_unc_imc.3 libpfm_intel_hswep_unc_irp.3 libpfm_intel_hswep_unc_pcu.3 libpfm_intel_hswep_unc_qpi.3 libpfm_intel_hswep_unc_r2pcie.3 libpfm_intel_hswep_unc_r3qpi.3 libpfm_intel_hswep_unc_sbo.3 libpfm_intel_hswep_unc_ubo.3 libpfm_intel_bdx_unc_cbo.3 libpfm_intel_bdx_unc_ha.3 libpfm_intel_bdx_unc_imc.3 libpfm_intel_bdx_unc_irp.3 libpfm_intel_bdx_unc_pcu.3 libpfm_intel_bdx_unc_qpi.3 libpfm_intel_bdx_unc_r2pcie.3 libpfm_intel_bdx_unc_r3qpi.3 libpfm_intel_bdx_unc_sbo.3 libpfm_intel_bdx_unc_ubo.3 libpfm_intel_skx_unc_cha.3 libpfm_intel_skx_unc_imc.3 libpfm_intel_skx_unc_irp.3 libpfm_intel_skx_unc_m2m.3 libpfm_intel_skx_unc_m3upi.3 libpfm_intel_skx_unc_pcu.3 libpfm_intel_skx_unc_ubo.3 libpfm_intel_skx_unc_upi.3 pfm_get_perf_event_encoding.3 libpfm_perf_event_raw.3 /usr/local/share/man/man3 )
make[1]: Leaving directory '/home/username/libpfm4/docs'
I can now see the library in /usr/local/libpfm.{a,so,so.4,so.4.11.1}.
Compiling the program
#include <stdio.h>
#include <perfmon/pfmlib.h>
int main(int argc, char **argv){
int idx;
pfm_os_t os;
pfm_event_info_t info;
idx = 239075328;
os = PFM_OS_NONE;
pfm_initialize();
pfm_get_event_info(idx, os, &info);
printf("Name: %s\n"
"Desc: %s\n"
"Equiv: %s\n"
"Code: %lu\n"
"IDX: %d\n"
"Attr: %d\n",
info.name,
info.desc,
info.equiv,
info.code,
info.idx,
info.nattrs);
return 0;
}
I use this to compile:
gcc -lpfm -Wall -Werror -std=gnu11 -pthread -g -o0 -fno-omit-frame-pointer -I include -o out.bin code.c
I get a clean output.
Running the program
$ ./out.bin
./out.bin: error while loading shared libraries: libpfm.so.4: cannot open shared object file: No such file or directory
If I use ldd, I get this:
$ ldd out.bin
linux-vdso.so.1 (0x00007ffc8f9fe000)
libpfm.so.4 => not found
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fdcdcf0b000)
libc.so.6 => /lib64/libc.so.6 (0x00007fdcdcd40000)
/lib64/ld-linux-x86-64.so.2 (0x00007fdcdcf44000)
What may I be missing?
There's a difference between the link-time path to a library and the run-time path.
Since the library is in a location that (apparently) isn't handled by the run-time loader you must add a flag when linking to tell the linker to add information about it in the executable for the run-time loader to check.
This is done with the -rpath linker specific flag.
You can pass it using gcc with the -Wl option:
gcc ... -Wl,-rpath=/usr/local/lib -L/usr/local/lib -lpfm
Related
i have recently started to use netbeans to program in c. i usually use codeblocks. i have installed tdm-gcc and msys for this purpose.
the programs are getting compiled successfully. but on execution, it shows build failed(exit value 2).
"/C/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/f/NetBeansProjects/C_Programs'
"/C/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_TDM-Windows/c_programs.exe
make.exe[2]: Entering directory `/f/NetBeansProjects/C_Programs'
mkdir -p build/Debug/MinGW_TDM-Windows
rm -f "build/Debug/MinGW_TDM-Windows/main.o.d"
gcc -c -g -MMD -MP -MF "build/Debug/MinGW_TDM-Windows/main.o.d" -o build/Debug/MinGW_TDM-Windows/main.o main.c
mkdir -p dist/Debug/MinGW_TDM-Windows
gcc -o dist/Debug/MinGW_TDM-Windows/c_programs build/Debug/MinGW_TDM-Windows/main.o build/Debug/MinGW_TDM-Windows/structure_union.o
build/Debug/MinGW_TDM-Windows/structure_union.o: In function `main':
F:\NetBeansProjects\C_Programs/structure_union.c:32: multiple definition of `main'
build/Debug/MinGW_TDM-Windows/main.o:F:\NetBeansProjects\C_Programs/main.c:15: first defined here
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW_TDM-Windows/c_programs.exe] Error 1
make.exe[2]: Leaving directory `/f/NetBeansProjects/C_Programs'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/f/NetBeansProjects/C_Programs'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 657ms)
can somebody help me with what im doing wrong?
You have multiple main() functions in your project:
[…]/structure_union.c:32: multiple definition of `main'
It seems there's one in structure_union and another one in main.c (line 15).
C allows only one definition of main(); remove one of these and it should work.
I have made a C program using libusb and I am using following command to compile it:
gcc -o usbtest.o usbtest.c -lusb-1.0
The program is working fine. Next, I added the code of "usbtest.c" to kernel module (usbmod.c) and I am stuck with the make file. I am not sure what command I should pass in the "all" section. Here is what I have made:
obj-m := usbmod.o
KERNEL_DIR = /lib/modules/$(shell uname -r)/build
PWD = $(shell pwd)
all:
$(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
clean:
rm -rf *.o *.ko *.mod.* *.symvers *.order *-
After running make, I am getting the following error:
anubhav#anubhav-Inspiron-3421:~/Desktop/usb$ make
make -C /lib/modules/3.13.0-46-generic/build SUBDIRS=/home/anubhav/Desktop/usb modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-46-generic'
CC [M] /home/anubhav/Desktop/usb/usbmod.o
/home/anubhav/Desktop/usb/usbmod.c:3:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
make[2]: *** [/home/anubhav/Desktop/usb/usbmod.o] Error 1
make[1]: *** [_module_/home/anubhav/Desktop/usb] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-46-generic'
make: *** [all] Error 2
Not sure if need to bring any header file to my working directory or what. Kindly provide suggestions.
Okay, so this link clarifies my doubts to some extent:
[][1]error: stdio.h: No such file or directory error during make
It says "stdio.h" and all do not exist in kernel space and therefore such errors arise. Besides, obviously my module does not contain any printf so I suppose I don't need "stdio.h".
But it does use libusb extensively. So, is there a way to really create this module.
My problem is the following one:
When installing Axis2/c under the guidance of http://petio.org/ws/web_services_page7.html , which seems to be an adjusted manual from the official site I have a problem right after executing the make command in terminal.
At exactly this point:
$ cd /tmp/axis/axis2c-src-1.6.0
$ ./configure --prefix=${AXIS2C_HOME} --enable-libxml2=yes
$ make
I get this error:
XXX#XXXPC:~/Tools/axis2c/axis2c-src-1.5.0$ make
make all-recursive
make[1]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0'
Making all in util
make[2]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
make all-recursive
make[3]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
Making all in src
make[4]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src'
Making all in platforms/unix
make[5]: Entering directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src/platforms/unix'
/bin/bash ../../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../include -I../../../include/platforms -I../../../include/platforms/unix -g -O2 -D_LARGEFILE64_SOURCE -ansi -Wall -Werror -Wno-implicit-function-declaration -D_GNU_SOURCE -MT uuid_gen_unix.lo -MD -MP -MF .deps/uuid_gen_unix.Tpo -c -o uuid_gen_unix.lo uuid_gen_unix.c
gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../include -I../../../include/platforms -I../../../include/platforms/unix -g -O2 -D_LARGEFILE64_SOURCE -ansi -Wall -Werror -Wno-implicit-function-declaration -D_GNU_SOURCE -MT uuid_gen_unix.lo -MD -MP -MF .deps/uuid_gen_unix.Tpo -c uuid_gen_unix.c -fPIC -DPIC -o .libs/uuid_gen_unix.o
**uuid_gen_unix.c: In function ‘axutil_uuid_gen_v1’:
uuid_gen_unix.c:62:20: error: variable ‘tv’ set but not used [-Werror=unused-but-set-variable]**
cc1: all warnings being treated as errors
make[5]: *** [uuid_gen_unix.lo] Error 1
make[5]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src/platforms/unix'
make[4]: *** [all-recursive] Error 1
make[4]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util/src'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0/util'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/XXX/Tools/axis2c/axis2c-src-1.5.0'
make: *** [all] Error 2
I am not able to understand the reason why this error is being produced.
Because 1.6.0 version is down, I am using the 1.5.0 source version of axis2/c from the official site : http://axis.apache.org/axis2/c/core/download.cgi .
I have additionally installed Apache2 and libxml2, OpenSSL, cURL, libiconv, and zlib.
libraries.
I need your help because I am trying to build a serious project.
Thanks in advance.
Link to mirror of original Axis2/C-1.6.0 source distribution is here.
The main problem is with -Werror flag.
To compile original Axis2/C with modern compiler you must remove -Werror string from build scripts. To do that run this command after unpacking tarball:
find -type f -name configure -exec sed -i '/CFLAGS/s/-Werror//g' {} \;
Then configure and make Axis2/C.
Note: Original Axis2/C-1.6.0 has many issues like memory leaks and crashes. Consider using Axis2/C unofficial project instead. Most critical Axis2/C-1.6.0's issues is fixed within that project.
Also it have additional features https://code.google.com/p/axis2c-unofficial/wiki/IssuesList like JSON support and enhanced CURL-based transport authentication (and some other features).
There is an manual on how to install Axis2/C unofficial on Linux.
The following make output is showing an undefined reference, and I am not sure what is causing it. Could someone help?
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/mongodrivertest.exe
make[2]: Entering directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f build/Debug/Cygwin_4.x-Windows/main.o.d
gcc -std=c99 -c -g -I../mongodb-mongo-c-driver/src/\*.c -MMD -MP -MF build/Debug/Cygwin_4.x-Windows/main.o.d -o build/Debug/Cygwin_4.x-Windows/main.o main.c
mkdir -p dist/Debug/Cygwin_4.x-Windows
gcc -std=c99 -o dist/Debug/Cygwin_4.x-Windows/mongodrivertest build/Debug/Cygwin_4.x-Windows/main.o
nbproject/Makefile-Debug.mk:61: recipe for target `dist/Debug/Cygwin_4.x-Windows/mongodrivertest.exe' failed
make[2]: Leaving directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
nbproject/Makefile-Debug.mk:58: recipe for target `.build-conf' failed
make[1]: Leaving directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
build/Debug/Cygwin_4.x-Windows/main.o: In function `main':
/cygdrive/g/workspace/c_cpp/MongoDriverTest/main.c:19: undefined reference to `_mongo_connect'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/mongodrivertest.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
And this is the content of my main.c:
#include <stdio.h>
#include <stdlib.h>
#include "../mongodb-mongo-c-driver/src/mongo.h"
int main(int argc, char** argv) {
int status;
mongo conn[1];
status=mongo_connect(conn, "127.0.0.1", 27017);
return EXIT_SUCCESS;
}
It was working two days ago, I reinstalled the OS and now it's not working anymore and I don't seem to find the cause. mongo.h exists, mongo.o is there as well. mongo_connect is in mongo.c. Any idea?
Your link line is:
gcc -std=c99 -o dist/Debug/Cygwin_4.x-Windows/mongodrivertest build/Debug/Cygwin_4.x-Windows/main.o
It doesn't tell GCC where to collect mongo_connect() from. You need to specify the Mongo library on the command line.
Given the include line in your source code:
#include "../mongodb-mongo-c-driver/src/mongo.h"
You might add options:
-L../mongodb-mongo-c-driver/lib -lmongo
to the link line. Both the location and the library name are guesses. That would pick up libmongo.dll or libmongo.lib from the specified directory.
If you can't find the library under the ../mongodb-mongo-c-driver directory, somewhere, you may have to build and install it. Alternatively, it may already be installed and you simply need to ensure you are referencing the correct locations where it is installed.
Also, as a general rule, avoid pathnames like that in the source code. You should specify:
#include "mongo.h"
and supply a compile line option to specify where to look for it:
-I../mongodb-mongo-c-driver/src
See also: What are the benefits of a relative path such as #include "../include/header.h" for a header?.
I installed netbeans to write code in C. But there is problem using Mingw compilers. It works just fine, till i try to run the project.
First it was unable to find cc1.exe while trying to run it. When i found it and manually copied into the same folder there is just another error.
"C:/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
C:\bin\make.exe[1]: Entering directory `D:/1/2/Skola/IZP/programovani/projekt4netbeans/CppApplication_6'
"C:/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_1-Windows/cppapplication_6.exe
C:\bin\make.exe[2]: Entering directory `D:/1/2/Skola/IZP/programovani/projekt4netbeans/CppApplication_6'
mkdir -p build/Debug/MinGW_1-Windows
rm -f build/Debug/MinGW_1-Windows/main.o.d
gcc.exe -c -g -MMD -MP -MF build/Debug/MinGW_1-Windows/main.o.d -o build/Debug/MinGW_1-Windows/main.o main.c
cc1: error: command line option '-lang-c' is valid for the driver but not for C
C:\bin\make.exe[2]: *** [build/Debug/MinGW_1-Windows/main.o] Error 1
C:\bin\make.exe[2]: Leaving directory `D:/1/2/Skola/IZP/programovani/projekt4netbeans/CppApplication_6'
C:\bin\make.exe[1]: *** [.build-conf] Error 2
C:\bin\make.exe[1]: Leaving directory `D:/1/2/Skola/IZP/programovani/projekt4netbeans/CppApplication_6'
C:\bin\make.exe: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
if someone could help me with that.. thanks :)
Make shure you have current versions of Netbeans and MinGw and that you have a correct installation (Configuring the NetBeans IDE for C/C++/Fortran).
On mingw you should not use make from mingw/bin, but the one from msys (<mingw>/msys/1.0/bin/make.exe)