Comments (7)
I remember reading the explanation for this somewhere, but can't remember now from the top of my head. When compiling and linking on the same line, put the source file first, linking flags and paths second.
It depends on the OS. On some older linux distros (and ubuntu undid the GCC patch for this... 🙄) the static linker is a bit finicky. Here's how it works:
- Process arguments from left to right
- Look at the object code (i.e. output of compiling test_dt.f90 or the current library archive file) of the thing being examined
- Keep any used symbols, symbols needed by other entities already processed (to the left) of this entity
- Construct a list of unresolved symbols and entities to search for when processing items to the right
- Discard any unused symbols and entities
This means that if a library or program needs to call a procedure declared in a different library, then it should appear to the left of that other library on the link line.
from datetime-fortran.
The issue is your compilation line: you pass a bunch of flags, but none to actually link in the datetime library.
Look inside /home/rfapostolo/code/proper/datetime-fortran/lib
for a file named something like libdatetime.a
(or ending in .so
etc.)
If you find that library, say libdatetime.a
, then you should add the following flag to your compile line after the -L/home/...
flag: -ldatetime
(Or just pass the absolute path to the library... that should work too.)
Let me break down the flags that you are currently passing and what they do:
-o test_dt
: Name the output executabletest_dt
-g
: generate debug symbol info (not really needed here, but doesn't hurt)-I/home/rfapostolo/code/datetime-fortran/include
look for include files and fortran.mod
files in this directory-I/home/rfapostolo/code/datetime-fortran/include
tell the linker to look in this directory when searching for libraries specified with the usual-lfoo
syntax-lmy_lib
: link againstlibmy_lib
(either the static library,libmy_lib.a
or a shared librarylibmy_lib.so
) somewhere on the library search path (system library directories like /usr/lib and places specified with-L/some/path
.
from datetime-fortran.
HI again,
I tried adding the -ldatetime
flag but the result was the same. I tried linking the library directly with L/.../lib/libdatetime
and L/.../lib/libdatetime.a
, but again got the same result.
I really appreciate the help and I'm sorry for wasting your time with this.
from datetime-fortran.
Hi Rui,
Does the following work? (put the program file before the linking flag)
f95 test_dt.f08 -o test_dt -g -I/home/rfapostolo/code/datetime-fortran/include -L/home/rfapostolo/code/proper/datetime-fortran/lib -ldatetime
I remember reading the explanation for this somewhere, but can't remember now from the top of my head. When compiling and linking on the same line, put the source file first, linking flags and paths second.
from datetime-fortran.
Hi Rui,
I'm not sure what's going on on your system. For me, I installed datetime-fortran through mac Homebrew (brew install datetime-fortran
), and was able to compile your test program as follows:
$ gfortran -o test_dt -g -I/usr/local/opt/datetime-fortran/include -L/usr/local/opt/datetime-fortran/lib test_dt.f90 -ldatetime
$ ./test_dt
2013 1 2
It's possible that you need to list the library to the right of your source file due to the way the static linker works on some OSes.
Also, I would recommend that:
- You name any modern (free source form, Fortran 90 onwords) Fortran source file with a
.f90
file extension - You call GFortran or whatever your Fortran compiler is directly, not through some system stub like
f95
- You confirm that datetime-fortran was compiled with the same compiler being used to build and link your code: Fortran .mod files are not compatible between compilers, and sometimes even between major releases of the same compiler.
If you have installed datetime-fortran into a default system location, or configure package-config to find the pc file for datetime-fortran you can get the include flags and the link flags needed to build against it using pkg-config
:
gfortran -o test_dt -g $(pkg-config --cflags datetime-fortran) test_dt.f90 $(pkg-config --libs datetime-fortran)
from datetime-fortran.
Hi @zbeekman and @milancurcic ,
I had no idea the compiler was reading the symbols left to right, but I can't say it doesn't make sense.
That was my problem, and having my code before the library worked perfectly.
Thank you very much for your help and suggestions, and apologies for the stupid mistake.
from datetime-fortran.
No worries, the left-to-right thing bites even the most experienced programmers from time to time.
The linker does this to increase speed and decrease memory footprint IIRC, and on macOS and some distros it's a complete non-issue. But on certain/most linux distros the linker throws out un-needed symbol info and definitions as it processes, only keeping a table of symbols that have been seen, but not yet defined in memory as it processes the files. When you link dynamically the order doesn't matter, but then you need to find a sane way to deal with loading the libs at runtime.
from datetime-fortran.
Related Issues (20)
- Document building with cmake and autotools HOT 1
- Define output (write) methods for datetime and timedelta instances HOT 1
- strptime does not handle errors HOT 1
- Cannot set seconds or others of timedelta HOT 3
- strptime does not zero tm struct before calling c_strptime HOT 1
- Error invoking datetime constructor with ifort-17.0.5 HOT 10
- Very strange (possibly compiler) bug with date2num HOT 3
- incorrect literal with REAL64 kind HOT 8
- add support for mingw HOT 1
- Can't build tests on win-ifort. Fails on linker with strptime HOT 4
- Building with autotools (not all libs are copied) HOT 9
- Dealing with huge timedelta values HOT 5
- Generic procedure including a sub-class of TimeDelta HOT 3
- Bug in function now() HOT 2
- Strptime Undefined Reference Error HOT 7
- Hour comparison in num2date is incorrect HOT 2
- Function that ingests ISO format and returns datetime? HOT 1
- CMake uses different compiler flags to autotools HOT 6
- Processing of `secondsSinceEpoch` and its reverse processing routine. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datetime-fortran.