Link errors building on Windows 10
spacioustime opened this issue · 9 comments
OS: Windows 10
Used OSGeo4W Setup to get proj-devel 8.1.0-1
Generator VS Build Tools 2019 x64
I set PROJINC and PROJLIB explictly
I get:
cmake --build target/cmake
Microsoft (R) Build Engine version 16.11.1+3e40a09f8 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Checking Build System
Building Custom Rule C:/dev/Scratch/PROJ-JNI/src/main/cpp/CMakeLists.txt
assertions.cpp
bindings.cpp
C:\dev\Scratch\PROJ-JNI\src\main\cpp\bindings.cpp(1165,80): warning C4267: 'return': conversion from 'size_t' to 'jint', possible loss of data [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
C:\dev\Scratch\PROJ-JNI\src\main\cpp\bindings.cpp(1168,76): warning C4267: 'return': conversion from 'size_t' to 'jint', possible loss of data [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
C:\dev\Scratch\PROJ-JNI\src\main\cpp\bindings.cpp(1171,92): warning C4267: 'return': conversion from 'size_t' to 'jint', possible loss of data [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
C:\dev\Scratch\PROJ-JNI\src\main\cpp\bindings.cpp(1174,92): warning C4267: 'return': conversion from 'size_t' to 'jint', possible loss of data [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
C:\dev\Scratch\PROJ-JNI\src\main\cpp\bindings.cpp(1177,97): warning C4267: 'return': conversion from 'size_t' to 'jint', possible loss of data [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
C:\dev\Scratch\PROJ-JNI\src\main\cpp\bindings.cpp(1180,103): warning C4267: 'return': conversion from 'size_t' to 'jint', possible loss of data [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
C:\dev\Scratch\PROJ-JNI\src\main\cpp\bindings.cpp(1698,28): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
C:\dev\Scratch\PROJ-JNI\src\main\cpp\bindings.cpp(1854,39): warning C4267: 'return': conversion from 'size_t' to 'int', possible loss of data [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
C:\dev\Scratch\PROJ-JNI\src\main\cpp\bindings.cpp(1884,39): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
C:\dev\Scratch\PROJ-JNI\src\main\cpp\bindings.cpp(1884,39): warning C4267: 'initializing': conversion from 'size_t' to 'const int', possible loss of data [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
Generating Code...
Creating library C:/dev/Scratch/PROJ-JNI/target/cmake/Debug/proj-binding.lib and object C:/dev/Scratch/PROJ-JNI/target/cmake/Debug/proj-binding.exp
bindings.obj : error LNK2001: unresolved external symbol pj_release [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const osgeo::proj::metadata::Identifier::CODE_KEY" (?CODE_KEY@Identifier@metadata@proj@osgeo@@2v?$basic_string
@du?$char_traits@D@std@@v?$allocator@D@2@@std@@b) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const osgeo::proj::metadata::Identifier::CODESPACE_KEY" (?CODESPACE_KEY@Identifier@metadata@proj@osgeo@@2v?$ba
sic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@b) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class osgeo::proj::common::UnitOfMeasure const osgeo::proj::common::UnitOfMeasure::SCALE_UNITY" (?SCALE_UNITY@UnitOfMeasure@common@proj@osgeo@@2V1234@B) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-bi
nding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class osgeo::proj::common::UnitOfMeasure const osgeo::proj::common::UnitOfMeasure::PARTS_PER_MILLION" (?PARTS_PER_MILLION@UnitOfMeasure@common@proj@osgeo@@2V1234@B) [C:\dev\Scratch\PROJ-JNI\target\c
make\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class osgeo::proj::common::UnitOfMeasure const osgeo::proj::common::UnitOfMeasure::METRE" (?METRE@UnitOfMeasure@common@proj@osgeo@@2V1234@B) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxpro
j]
bindings.obj : error LNK2001: unresolved external symbol "public: static class osgeo::proj::common::UnitOfMeasure const osgeo::proj::common::UnitOfMeasure::RADIAN" (?RADIAN@UnitOfMeasure@common@proj@osgeo@@2V1234@B) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxp
roj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class osgeo::proj::common::UnitOfMeasure const osgeo::proj::common::UnitOfMeasure::MICRORADIAN" (?MICRORADIAN@UnitOfMeasure@common@proj@osgeo@@2V1234@B) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-bi
nding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class osgeo::proj::common::UnitOfMeasure const osgeo::proj::common::UnitOfMeasure::DEGREE" (?DEGREE@UnitOfMeasure@common@proj@osgeo@@2V1234@B) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxp
roj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class osgeo::proj::common::UnitOfMeasure const osgeo::proj::common::UnitOfMeasure::ARC_SECOND" (?ARC_SECOND@UnitOfMeasure@common@proj@osgeo@@2V1234@B) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-bind
ing.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class osgeo::proj::common::UnitOfMeasure const osgeo::proj::common::UnitOfMeasure::GRAD" (?GRAD@UnitOfMeasure@common@proj@osgeo@@2V1234@B) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class osgeo::proj::common::UnitOfMeasure const osgeo::proj::common::UnitOfMeasure::SECOND" (?SECOND@UnitOfMeasure@common@proj@osgeo@@2V1234@B) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxp
roj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class osgeo::proj::common::UnitOfMeasure const osgeo::proj::common::UnitOfMeasure::YEAR" (?YEAR@UnitOfMeasure@common@proj@osgeo@@2V1234@B) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const osgeo::proj::common::IdentifiedObject::NAME_KEY" (?NAME_KEY@IdentifiedObject@common@proj@osgeo@@2v?$basi
c_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@b) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const osgeo::proj::common::IdentifiedObject::IDENTIFIERS_KEY" (?IDENTIFIERS_KEY@IdentifiedObject@common@proj@o
sgeo@@2v?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@b) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const osgeo::proj::common::IdentifiedObject::ALIAS_KEY" (?ALIAS_KEY@IdentifiedObject@common@proj@osgeo@@2v?$ba
sic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@b) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const osgeo::proj::common::IdentifiedObject::REMARKS_KEY" (?REMARKS_KEY@IdentifiedObject@common@proj@osgeo@@2v
?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@b) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const osgeo::proj::common::IdentifiedObject::DEPRECATED_KEY" (?DEPRECATED_KEY@IdentifiedObject@common@proj@osg
eo@@2v?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@b) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const osgeo::proj::common::ObjectUsage::SCOPE_KEY" (?SCOPE_KEY@ObjectUsage@common@proj@osgeo@@2v?$basic_string
@du?$char_traits@D@std@@v?$allocator@D@2@@std@@b) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const osgeo::proj::datum::Ellipsoid::EARTH" (?EARTH@Ellipsoid@datum@proj@osgeo@@2v?$basic_string@DU?$char_trai
ts@D@std@@v?$allocator@D@2@@std@@b) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
bindings.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits,class std::allocator > const osgeo::proj::datum::TemporalDatum::CALENDAR_PROLEPTIC_GREGORIAN" (?CALENDAR_PROLEPTIC_GREGORIAN@Temporal
Datum@datum@proj@osgeo@@2v?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@b) [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
C:\dev\Scratch\PROJ-JNI\target\cmake\Debug\proj-binding.dll : fatal error LNK1120: 21 unresolved externals [C:\dev\Scratch\PROJ-JNI\target\cmake\proj-binding.vcxproj]
I have attached the full console log of my attempt to build:
build_log.txt
Hi, I've set PROJLIB to \lib\proj.lib. This worked.
Thanks for the update. I will close this issue then.
BTW: Using PROJ-JNI on Windows requires additional setup:
For compilation you need to set PROJLIB and PROJINC manually since 'find_library(PROJLIB proj)' doesn't seem to work here.
For runtime you also need to load all libraries that proj-binding.dll depends on (proj_9_1.dll, sqlite3.dll etc.) via System.load("...").
Thanks for the clarification. For PROJLIB
and PROJINC
, would it be possible to provide an example that we could put in the README
? And regarding System.load(…)
, I do not have in mind the exact sentence used in the code, but could you provide an example as well so we can compare with what the code currently does?
I'm not very familiar to cmake so I've patched CMakelist.txt like this:
...
# We want the "local/lib/" directory to be checked first in order to link against the PROJ version compiled
# locally. Otherwise the PROJ version installed by the package manager may have precedence on Linux systems.
# CMake searches the path in the desired order when using this directive.
find_library(PROJLIB proj)
# set it explicitly on Windows because find_library() doesn't seem to work here
set (PROJLIB $ENV{OSGEO4W_DIR}/lib/proj.lib)
set (PROJINC $ENV{OSGEO4W_DIR}/include)
and provide OSGEO4W_DIR as env-variable at command line. But may be there es better solution. I think it could also be provided via command line parameter to cmake like this:
cmake ... -DPROJLIB=... -DPROJINC=...
but then you need to patch the Ant-file build.xml.
Regarding the System.load("..."):
org.osgeo.proj.NativeResource loads only proj-bindung.dll from the Jar in its static{} block. I've added to my code the following before NativeResource is used:
System.load("/path/to/sqlite3.dll");
System.load("/path/to/libcurl.dll");
System.load("/path/to/zlib1.dll");
System.load("/path/to/jpeg62.dll");
System.load("/path/to/lzma.dll");
System.load("/path/to/tiff.dll");
System.load("/path/to/proj_9_1.dll");
where "/path/to" is also a temporary directory that is created when the DLLs are unpacked from my Jar like proj-bindung.dll.
Is the above section about accurate?
https://github.com/OSGeo/PROJ-JNI/wiki/Install#build-and-run-in-windows-environment
It's not necessary to patch NativeResource. Loading the DLLs can be done also outside PROJ-JNI anywhere in the application before PROJ-JNI is used. But the description is fine, I think.
Thanks for the review. Updated the wiki accordingly.
@ggmuelle i am facing this issue on windows 11, could you guide me
PS F:\PROJ-JNI> mvn clean package -DskipTests
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< org.osgeo:proj >---------------------------
[INFO] Building PROJ bindings 2.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- clean:3.2.0:clean (default-clean) @ proj ---
[INFO] Deleting F:\PROJ-JNI\target
[INFO]
[INFO] --- enforcer:3.4.1:enforce (enforce) @ proj ---
[INFO] Rule 0: org.apache.maven.enforcer.rules.version.RequireJavaVersion passed
[INFO] Rule 1: org.apache.maven.enforcer.rules.dependency.DependencyConvergence passed
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ proj ---
[INFO] Copying 1 resource from src\main\resources to target\classes
[INFO]
[INFO] --- compiler:3.13.0:compile (default-compile) @ proj ---
[INFO] Compiling 49 source files with javac [debug deprecation release 11 module-path] to target\classes
[INFO]
[INFO] --- antrun:3.1.0:run (build-native) @ proj ---
[INFO] Executing tasks
[INFO] [mkdir] Created dir: F:\PROJ-JNI\target\cmake
[INFO] [exec] -- Configuring done (0.4s)
[INFO] [exec] -- Generating done (0.1s)
[INFO] [exec] -- Build files have been written to: F:/PROJ-JNI/src/main/cpp
[INFO] [exec] Error: could not load cache
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.540 s
[INFO] Finished at: 2024-09-30T17:37:08+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:3.1.0:run (build-native) on project proj: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] F:\PROJ-JNI\src\main\cpp\build.xml:42: exec returned: 1
[ERROR] around Ant part ...<ant antfile="F:\PROJ-JNI/src/main/cpp/build.xml" inheritAll="true" dir="${target.directory}" />... @ 7:101 in F:\PROJ-JNI\target\antrun\build-main.xml