Linker error (can't find -lproj) after compiling proj on FreeBSD

145 views
Skip to first unread message

KonstantinS

unread,
Aug 19, 2016, 8:52:13 AM8/19/16
to Iris
Hi,

I have compiled and installed current proj4 with prefix set to $HOME/local, so I see its .h files in $HOME/local/include. Trying to compile cartopy fails with this:

python3.5 setup.py build_ext --inplace -I$HOME/local/include -L$HOME/local/include
[…]
lib
/cartopy/trace.cpp:3136:12: warning: will never be executed [-Wunreachable-code]
           
break;
           
^~~~~
70 warnings generated.
cc
-Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fPIC -I/usr/local/include -I./lib/cartopy -I/usr/local/include -I/home/yggdrasil/local/include -I/usr/local/include/python3.5m -c lib/cartopy/_trace.cpp -o build/temp.freebsd-10.3-RELEASE-p4-amd64-3.5/lib/cartopy/_trace.o
c
++ -shared build/temp.freebsd-10.3-RELEASE-p4-amd64-3.5/lib/cartopy/trace.o build/temp.freebsd-10.3-RELEASE-p4-amd64-3.5/lib/cartopy/_trace.o -L/usr/local/lib -L/usr/local/lib -L/home/yggdrasil/local/include -L/usr/local/lib -Wl,-rpath=/usr/local/lib -lproj -lgeos_c -lpython3.5m -o /storage/code/cartopy/lib/cartopy/trace.so
/usr/bin/ld: cannot find -lproj
c
++: error: linker command failed with exit code 1 (use -v to see invocation)
error
: command 'c++' failed with exit status 1

My C knowledge is rather limited, so any advise is welcome. System is FreeBSD10.3, compiler is clang. Changing to
CC=gcc GCC=g++ python3.5 …
gives same linker error.

Andrew Dawson

unread,
Aug 19, 2016, 11:56:12 AM8/19/16
to Iris
You have specified the directory containing the includes twice instead of the includes with -I and the library directory with -L. Replace this part:

-I$HOME/local/include -L$HOME/local/include

with this:

-I$HOME/local/include -L$HOME/local/lib

KonstantinS

unread,
Aug 19, 2016, 7:42:19 PM8/19/16
to Iris
Yikes, that's quite a stupid mistake to make, thank you.
Unfortunately after a successfull built_ext now the install part errors out:

python3.5 setup.py install --user
running install
running bdist_egg
running egg_info
writing top
-level names to lib/Cartopy.egg-info/top_level.txt
writing requirements to lib
/Cartopy.egg-info/requires.txt
writing dependency_links to lib
/Cartopy.egg-info/dependency_links.txt
writing lib
/Cartopy.egg-info/PKG-INFO
reading manifest file
'lib/Cartopy.egg-info/SOURCES.txt'
reading manifest
template 'MANIFEST.in'
warning
: no files found matching 'lib/cartopy/data/*'
writing manifest file
'lib/Cartopy.egg-info/SOURCES.txt'
installing library code to build
/bdist.freebsd-10.3-RELEASE-p4-amd64/egg
running install_lib
running build_py
running build_ext
skipping
'lib/cartopy/trace.cpp' Cython extension (up-to-date)
building
'cartopy.trace' extension
cc
-Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fPIC -I/usr/local/include -I./lib/cartopy -I/usr/local/include -I/usr/local/include/python3.5m -c lib/cartopy/trace.cpp -o build/temp.freebsd-10.3-RELEASE-p4-amd64-3.5/lib/cartopy/trace.o
lib
/cartopy/trace.cpp:282:10: fatal error: 'proj_api.h' file not found
#include "proj_api.h"
         
^
1 error generated.
error
: command 'cc' failed with exit status 1
It seems the built_ext command doesn't inform the install command about the extra locations to include headers from. While I can manually run the compile with the added -I, a " setup.py install" afterwards again runs the compile, failing once more.

Andrew Dawson

unread,
Aug 20, 2016, 10:20:51 AM8/20/16
to Iris
This is because you first build_ext used the --inplace flag, which builds the modules in the source tree, useful for developers. The install command will not find these, it wants to find them in the build directory, and will therefore have to re-run the build_ext command, but since you didn't give it any flags it won't find the things it needs. You should remove the --inplace flag from your first command to resolve this.
Reply all
Reply to author
Forward
0 new messages