I am trying to compile the code which is available online Non-Local Means Denoising
When I compile the source, the following errors appear that I suppose are mainly due to libpng:
g++ -L/opt/local/lib/ -L/usr/local/lib/ -L/usr/lib/x86_64-linux-gnu/ -fopenmp -lpng
-o nlmeans_ipol nlmeans_ipol.o io_png.o libauxiliar.o libdenoising.o mt19937ar.o
io_png.o: In function `io_png_write_raw':
io_png.c:(.text+0xe0): undefined reference to `png_create_write_struct'
io_png.c:(.text+0xf6): undefined reference to `png_create_info_struct'
io_png.c:(.text+0x12b): undefined reference to `png_init_io'
io_png.c:(.text+0x194): undefined reference to `png_set_IHDR'
io_png.c:(.text+0x1a6): undefined reference to `png_write_info'
io_png.c:(.text+0xb36): undefined reference to `png_write_image'
io_png.c:(.text+0xb48): undefined reference to `png_write_end'
io_png.c:(.text+0xb62): undefined reference to `png_destroy_write_struct'
io_png.c:(.text+0xbcc): undefined reference to `png_destroy_write_struct'
io_png.c:(.text+0xc1f): undefined reference to `png_destroy_read_struct'
io_png.c:(.text+0xe6a): undefined reference to `png_destroy_write_struct'
io_png.c:(.text+0xe80): undefined reference to `png_destroy_write_struct'
I have followed the following threads and placed the file "libpng.a" at many locations but it does not help.
I have seen a similar libpng problem here but does not help.
I am using ubuntu 12.04.
Could anyone please tell what could actually go wrong?
EDIT 1
The complete call is as follows
g++ -O3 -funroll-loops -fomit-frame-pointer -fno-tree-pre -falign-loops -ffast-math -ftree-vectorize -Wall -Wextra -Wno-write-strings -Wno-deprecated -ansi -fopenmp -c -o nlmeans_ipol.o nlmeans_ipol.cpp
cc -c -o io_png.o io_png.c -O3 -funroll-loops -fomit-frame-pointer -fno-tree-pre -falign-loops -ffast-math -ftree-vectorize -Wall -Wextra -Wno-write-strings -ansi -I/opt/local/include/ -I/usr/local/include/
g++ -c -o libauxiliar.o libauxiliar.cpp -O3 -funroll-loops -fomit-frame-pointer -fno-tree-pre -falign-loops -ffast-math -ftree-vectorize -Wall -Wextra -Wno-write-strings -Wno-deprecated -ansi -fopenmp -I/opt/local/include/ -I/usr/local/include/
g++ -c -o libdenoising.o libdenoising.cpp -O3 -funroll-loops -fomit-frame-pointer -fno-tree-pre -falign-loops -ffast-math -ftree-vectorize -Wall -Wextra -Wno-write-strings -Wno-deprecated -ansi -fopenmp -I/opt/local/include/ -I/usr/local/include/
cc -c -o mt19937ar.o mt19937ar.c -O3 -funroll-loops -fomit-frame-pointer -fno-tree-pre -falign-loops -ffast-math -ftree-vectorize -Wall -Wextra -Wno-write-strings -ansi -I/opt/local/include/ -I/usr/local/include/
g++ -lpng -lm -fopenmp -L/opt/local/lib/ -L/usr/local/lib/ -L/usr/lib/ -L/usr/lib/x86_64-linux-gnu/ -fopenmp -lpng -lpngwriter -lz -lfreetype -o nlmeans_ipol nlmeans_ipol.o io_png.o libauxiliar.o libdenoising.o mt19937ar.o
this is the complete call. Its a make file, The dump above in the copy of what appears at the command prompt.
Try just changing the sequence of parameters in your g++ call and have -lpng behind the object files. The linker evalueates the arguments in the sequence they are given so when it gets -lpng it has not yet knowledge of io_png.o and so it doesn't link the neccessary code from the library
Edit:
The last command of what your makefile executes is:
g++ -lpng -lm -fopenmp -L/opt/local/lib/ -L/usr/local/lib/ -L/usr/lib/ -L/usr/lib/x86_64-linux-gnu/ -fopenmp -lpng -lpngwriter -lz -lfreetype -o nlmeans_ipol nlmeans_ipol.o io_png.o libauxiliar.o libdenoising.o mt19937ar.o
If should be something like
g++ -L/opt/local/lib/ -L/usr/local/lib/ -L/usr/lib/ -L/usr/lib/x86_64-linux-gnu/ -o nlmeans_ipol nlmeans_ipol.o io_png.o libauxiliar.o libdenoising.o mt19937ar.o -lpng -lm -fopenmp -lpngwriter -lz -lfreetype
I don't know each of the libraries, maybe the sequence of the -l... parameters still isn't right
Related
I'm currently playing around with LTO for an embedded system (to see if it could reduce the size) and was having some issues getting everything to link properly using ld directly and was wondering what I was doing wrong. This is mostly playing with a toy program before I use this in a larger project.
The setup is basically I have 3 files:
test.c - data transform function
test_main.c - calls a function defined in start.S
start.S - calls a function in test.c and also contains _start
I compile the files using:
arm-none-eabi-as -mthumb -Wall start.S -o start.o
arm-none-eabi-gcc -Wall -Werror -march=armv7 -mtune=cortex-r7 -mthumb -fPIC -nostdlib -flto -static test.c -c test.o
arm-none-eabi-gcc -Wall -Werror -march=armv7 -mtune=cortex-r7 -mthumb -fPIC -nostdlib -flto -static test_main.c -c test_main.o
If I then try to link the program with ld I get:
arm-none-eabi-ld --static -fPIC --shared --fatal-warning test.o start.o test_main.o -test
arm-none-eabi-ld: test.o: plugin needed to handle lto object
arm-none-eabi-ld: test.o: plugin needed to handle lto object
arm-none-eabi-ld: test_main.o: plugin needed to handle lto object
arm-none-eabi-ld: test_main.o: plugin needed to handle lto object
If I use gcc though, it works:
arm-none-eabi-gcc -Wall -Werror -march=armv7 -mtune=cortex-r7 -mthumb -fPIC -nostdlib -flto -static test.o start.o test_main.o -o test.gcc
I have tried specifying the linker plugin directly but then I get a different error:
arm-none-eabi-ld --static -fPIC --shared --fatal-warning --plugin <path_to_correct>/liblto_plugin.so test.o start.o test_main.o -test
arm-none-eabi-ld: <path_to_correct>.../lto-plugin.c:741: all_symbols_read_handler: Assertion 'lto_wrapper_argv' failed.
Aborted (core dumped)
What flags, parameters, etc. am I missing in my ld call?
I have this code that compiles fine on my desktop, but when I try to compile it on the raspberry pi, I get this error
gcc -Wall -O2 -lGL -lGLU -lm -lSDL_image -lfftw3 -lftdi `sdl-config --cflags --libs` -c main.c
gcc -Wall -O2 -lGL -lGLU -lm -lSDL_image -lfftw3 -lftdi `sdl-config --cflags --libs` -c fft.c
gcc -Wall -O2 -lGL -lGLU -lm -lSDL_image -lfftw3 -lftdi `sdl-config --cflags --libs` -c draw.c
gcc -Wall -O2 -lGL -lGLU -lm -lSDL_image -lfftw3 -lftdi `sdl-config --cflags --libs` -c table.c
gcc -Wall -O2 -lGL -lGLU -lm -lSDL_image -lfftw3 -lftdi `sdl-config --cflags --libs` -c serial.c
gcc -Wall -O2 -lGL -lGLU -lm -lSDL_image -lfftw3 -lftdi `sdl-config --cflags --libs` main.o fft.o draw.o table.o serial.o -o main
/usr/bin/ld: Warning: size of symbol `table' changed from 2048 in
table.o to 204 in
//usr/lib/arm-linux-gnueabihf/pulseaudio/libpulsecommon-10.0.so
/usr/bin/ld: table.o: undefined reference to symbol 'table'
//usr/lib/arm-linux-gnueabihf/pulseaudio/libpulsecommon-10.0.so: error
adding symbols: DSO missing from command line collect2: error: ld
returned 1 exit status makefile:6: recipe for target 'main' failed
make: *** [main] Error 1
I've tried reinstalling libpulse0 and made sure pulseaudio was installed, and I can find the libpulsecommon-10.0.so when I search for it on the pi. So I'm not sure what to do from here.
libpulsecommon has a global symbol named table, and your code (probably table.c) also has a public symbol with this name. The symbols are colliding when linking. Rename that variable/function on your code.
I'm trying to compile the TPC-H Benchmark and when I made make, is returned the following error:
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o build.o build.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o driver.o driver.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o bm_utils.o bm_utils.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o rnd.o rnd.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o print.o print.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o load_stub.o load_stub.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o bcd2.o bcd2.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o speed_seed.o speed_seed.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o text.o text.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o permute.o permute.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o rng64.o rng64.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -O -o dbgen build.o driver.o bm_utils.o rnd.o print.o load_stub.o bcd2.o speed_seed.o text.o permute.o rng64.o -lm
ld: library not found for -lgcc
collect2: error: ld returned 1 exit status
make: *** [dbgen] Error 1
I made a search for trying to fix this and I don't found it any help yet. Somebody can help me please?
try using gcc-5 on your makefile. i had the same problem with tpc-h.
install.packages("ncdf")
* installing source package ‘ncdf’ ...
** package ‘ncdf’ successfully unpacked and MD5 sums checked checking for nc-config... /usr/local/bin/nc-config configure: creating
./config.status config.status: creating src/Makevars
** libs gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/local/include -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c ncdf.c -o ncdf.o gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I/usr/local/include
-fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c ncdf2.c -o ncdf2.o gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG
-I/usr/local/include -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c ncdf3.c -o ncdf3.o gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions
-Wl,-z,relro -o ncdf.so ncdf.o ncdf2.o ncdf3.o -L/usr/local/lib -lnetcdf -L/usr/lib/R/lib -lR /usr/bin/ld: /usr/local/lib/libnetcdf.a(attr.o): relocation R_X86_64_32 against
`.rodata' can not be used when making a shared object; recompile with
-fPIC /usr/local/lib/libnetcdf.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status make: *** [ncdf.so] Error 1
ERROR: compilation failed for package ‘ncdf’
* removing ‘/home/ayesha/R/x86_64-pc-linux-gnu-library/3.2/ncdf’
The downloaded source packages are in
'/tmp/RtmpSrzd8P/downloaded_packages'
My Makefile looks like this:
CC=gcc
CFLAGS=-Wall -Wextra -std=c99 -pedantic
OBJECTS=main.o Scene.o Matrix.o Vector.o Triangle.o Color.o Raster.o
render: $(OBJECTS)
$(CC) $(CFLAGS) -lm -o render -g $(OBJECTS)
rm $(OBJECTS)
clean:
rm -f render*
This builds my executable with no errors, but when I change -o to -o2 or -o3, I get the error:
gcc -Wall -Wextra -std=c99 -pedantic -c -o main.o main.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Scene.o Scene.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Matrix.o Matrix.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Vector.o Vector.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Triangle.o Triangle.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Color.o Color.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Raster.o Raster.c
gcc -Wall -Wextra -std=c99 -pedantic -lm -o3 render -g main.o Scene.o Matrix.o Vector.o Triangle.o Color.o Raster.o
gcc.exe: error: render: No such file or directory
make: *** [render] Error 1
There could be some error in my code detected by the optimization flags, but as I don't get any error messages before this it's hard to know what's going wrong. I'm using MinGW/MSYS on Windows 7.
-o render means create the output file with the name render.
Now you are changing this -o to -o3 which is incorrect. Instead you need to keep -o render as it is and add a -O3 flag for optimization. Note the capital letter O.
-o is the output file flag. You were thinking of -O (capital).