Compiling Fortran netCDF programs with all available libraries - compilation

first of all I've read this topic but I can't compile my code.
Compiling Fortran netCDF programs on Ubuntu
I am on UBUNTU 14.04 and compiling a fortran program that uses NetCDF. I have compilation error like this:
terrain.f:(.text+0x17efd): undefined reference to 'ncopn_'
terrain.f:(.text+0x18111): undefined reference to 'ncopn_'
terrain.f:(.text+0x187cc): undefined reference to 'ncclos_'
terrain.f:(.text+0x187ea): undefined reference to 'ncclos_'
Definitely it says I have not netcdf fortran librarries. But I installed zlib, HDF5, netcdf C and netcdf Fortran according these web pages with disable shared and disable dap options.
http://www.unidata.ucar.edu/software/netcdf/docs/build_default.html
http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-fortran-install.html
this is result of nc-config --libs command:
-L/usr/local/lib -L/usr/local -lnetcdf -lhdf5_hl -lhdf5 -ldl -lm -lz
this is result of nf-config --flibs command:
-L/usr/local/lib -lnetcdff -L/usr/local/lib -lnetcdf -lnetcdf -lhdf5_hl -lhdf5 -lz
i build my project with this command:
gfortran terrain.f -I/usr/local/include -L/usr/local/lib -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz -lm -ldl
what's wrong with this?
Edit: I use --disable-netcdf-4 option in configuring netcdf C and netcdf fortran and I can compile my code. So it's a problem with HDF5.

This isn't really an answer, but you need to produce more info. Write a bare-bones program, and show us the code. Then show us the command you use to try and compile.
Here are two examples:
Fortran 77:
$ cat test_nc.f
PROGRAM TEST_NC
IMPLICIT NONE
include 'netcdf.inc'
INTEGER ncid, nc_err
nc_err = nf_open('test.nc', nf_nowrite, ncid)
nc_err = nf_close(ncid)
END PROGRAM TEST_NC
$ gfortran test_nc.f -o test_nc `nf-config --fflags --flibs`
Fortran 90:
$ cat test_nc.f90
program test_nc
use netcdf
implicit none
integer :: ncid, nc_err
nc_err = nf90_open('test.nc', nf90_nowrite, ncid)
nc_err = nf90_close(ncid)
end program test_nc
$ gfortran test_nc.f90 -o test_nc `nf-config --fflags --flibs`
Both of these compile on my system without errors or even warnings.

Related

GCC undefined reference to thrd_create() in C11 mode after #include <threads.h> in Debian

I'm trying to compile a program that I've been able to compile on several other Debian environments with no issues using the C11 <threads.h> library on a relatively fresh install of Debian Bullseye with "gcc (Debian 10.2.1-6) 10.2.1 20210110" installed
with the command
gcc -o <progname> -O3 -Wall -Wextra -std=c11 -lpthread <sourcefile>
and I'm getting a string of linker errors in the form of
undefined reference to 'mtx_unlock'
as well as mtx_lock mtx_init thrd_create etc.
But I'm not getting an error saying the threads.h file is absent. I tried removing the -lpthread argument from the compilation command but this changed nothing.
What is going wrong?
The correct command line parameter seems to be -pthread without the l.

Error when cross compiling shared so which depends on another so

I am trying to cross compile my application for a arm based system.
I have 2 libraries compiled in the following way:
$ gcc -shared --sysroot=$DIR_PATH -o $LIBPATH/libfoo.so foo.o
$ gcc -shared --sysroot=$DIR_PATH -o $LIBPATH/libbar.so bar.o
A third library is compiled:
gcc -shared -o $LIBPATH/libfoobar.so --sysroot=$DIR_PATH -L$LIBPATH -Wl,rpath=$RUN_TIME_PATH foobar.o -lfoo -lbar
Then finally I compile a binary:
gcc -o app --sysroot=$DIR_PATH -L$LIBPATH -Wl,rpath=$RUN_TIME_PATH app.o -lfoobar
However when compiling app I get
warning: libfoo.so, needed by libfoobar.so, not found (try using -rpath or -rpath-link)
I believe you need to use -Wl,-rpath-link=$LIBPATH to tell the linker where to look to resolve runtime library references during the link operation.
More info can be found in the ld documentation: https://sourceware.org/binutils/docs-2.37/ld/Options.html

Compiling OpenMP to WebAssembly

I am trying to compile a multi threaded application to WebAssembly. The application uses OpenMP for multithreading.
To compile I am using the Emscripten framework.
I have already downloaded the source files for OpenMP and compiled it for my host machine using make. With the following command I can get it to link with a simple demo application on my machine:
g++ -Wall -Werror -pedantic main.o -o main.x /$PATH_TO_OPENMP/build/runtime/src/libgomp.a -pthread -lstdc++ -Wl,--no-as-needed -ldl
I then tried to compile OpenMP to the llvm bytecode format used by Emscripten. To do so I tried to run 'emmake make', so that the emscripten framework executes the OpenMP makefiles with a suitable compiler. As emscripten does not like shared object files I compiled it to static library .a files.
This works and actually gives me object files to which I can link.
I then wanted to link my demo application with the following command
em++ -Wall -Werror -pedantic main.o -o main.html /home/main/data/Programming/openMP/openmp_web/build/runtime/src/libgomp.a -pthread -lstdc++ -Wl,--no-as-needed -ldl
But I get these warnings, that it couldn't link to OpenMP files:
shared:WARNING: object /tmp/emscripten_temp_ONa0eU_archive_contents/kmp_atomic.cpp.o is not a valid object file for emscripten, cannot link
.
.
shared:WARNING: object /tmp/emscripten_temp_ONa0eU_archive_contents/kmp_str.cpp.o is not a valid object file for emscripten, cannot link
shared:WARNING: object /tmp/emscripten_temp_ONa0eU_archive_contents
So I figured I must have compiled OpenMP with the wrong compiler. I then tried to change the compiler when building the library by using the following commands:
cmake -DCMAKE_C_COMPILER=emcc -DCMAKE_CXX_COMPILER=em++ -DLIBOMP_LIB_TYPE=normal -DLIBOMP_ENABLE_SHARED=OFF -DCMAKE_BUILD_TYPE=Release -DLIBOMP_ARCH=x86_64 OPENMP_STANDALONE_BUILD=1 ..
emmake make
But this just gives strange errors on some missing system variables
/home/main/data/Programming/openMP/openmp_web/runtime/src/kmp_platform.h:82:2: error: Unknown OS
/home/main/data/Programming/openMP/openmp_web/runtime/src/kmp_platform.h:203:2: error: Unknown or unsupported architecture
In file included from /home/main/data/Programming/openMP/openmp_web/runtime/src/kmp_alloc.cpp:13:
In file included from /home/main/data/Programming/openMP/openmp_web/runtime/src/kmp.h:77:
/home/main/data/Programming/openMP/openmp_web/runtime/src/kmp_os.h:171:2: error: "Can't determine size_t printf format specifier."
Does anyone have an idea on what I could do differently?

FLTK compile error with gcc

I am trying to compile my first FLTK file. First I compiled it by gcc with -lfltk option, and I got this error:
/usr/bin/ld: /tmp/ccX7sPxQ.o: undefined reference to symbol '__gxx_personality_v0##CXXABI_1.3'
/usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Why do I get this error message? If I use g++ instead, it just compiles it.
edit.
fltk-config --cxxflags returns:
-I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
-I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12
-I/usr/include/freetype2 -I/usr/include/cairo -I/usr/include/glib-2.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2
-I/usr/include/libpng12 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT
-lfltk is not enough to build a minimal FLTK-based application.
I strongly suggest you to read the following page: http://www.fltk.org/doc-1.3/basics.html . It clearly explains how to compile a simple FLTK program.
Assuming your FLTK application is not using extra FLTK libraries (opengl, images, forms) and is in a single file, called myfltkapp.cpp, the absolutely quickest way to compile and link it properly would be:
fltk-config --compile myfltkapp.cpp
I guess the reason I got the error comes from the difference between gcc and g++. I thought I could compile it by gcc with fltk library, but gcc does not link c++ standard library automatically. Thus you have to include the C++ standard library for gcc. It was a silly question.
gcc myfltkapp.cpp -lstdc++ -lfltk
What is the difference between g++ and gcc?

Libxml2: undefined reference to xmlTextReaderConstName

I have installed the latest libxml2-2.8.0, as usual: $ ./configure, $ make, $ make install.
The $ xml2-config --cflags --libs gives this output:
-I/usr/local/include/libxml2
-L/usr/local/lib -lxml2 -lm
But trying to compile any example...
$ gcc `xml2-config --cflags --libs` xmltest.c
The linker says:
/tmp/cc8ezrPl.o: In function `processNode':
xmltest.c:(.text+0x19): undefined reference to `xmlTextReaderConstName'
xmltest.c:(.text+0x38): undefined reference to `xmlTextReaderConstValue'
...etc.
Anything I've googled can be solved by xml2-config --cflags --libs flags, or upgrading to the latest version of libxml2, or something. Unfortunately, neither works for me.
What can be the steps to identify the problem?
Using Ubuntu 12.04 64-bit.
The libraries should be specified only after the source file so that the linker can resolve the undefined references in the source file. Try compiling the example with this
gcc -I/usr/local/include/libxml2 -L/usr/local/lib xmltest.c -lxml2 -lm

Resources