Skip to content

How do I link GDAL to library compile #8664

@am2222

Description

@am2222

Hi,
I want to compile a library which is using gdal and I have to link it, I am currently adding vcpkg\installed\x86-windows\include to the include directory and also added vcpkg\installed\x86-windows\lib as libraries directory into my setup.py file. but it still raises liker error

d:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /nodefaultlib:libucrt.lib ucrt.lib /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:C:\Program Files\Python36\libs" "/LIBPATH:C:\Program Files\Python36\PCbuild\amd64" "/LIBPATH:d:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.7.2\lib\um\x64" "/LIBPATH:D:\Windows Kits\10\lib\10.0.17763.0\ucrt\x64" "/LIBPATH:D:\Windows Kits\10\lib\10.0.17763.0\um\x64" /LIBPATH:E:\Personal\SideWorks\vcpkg\installed\x86-windows\lib gdal.lib geos.lib geos_c.lib /EXPORT:PyInit_pydggrid build\temp.win-amd64-3.6\Release\Personal\Lab\DGGRID\pydggrid-master\src\main.obj build\temp.win-amd64-3.6\Release\Personal\Lab\DGGRID\pydggrid-master\src\lib\dggrid\binpres.obj .
.
.
.
build\temp.win-amd64-3.6\Release\Personal\Lab\DGGRID\pydggrid-master\src\lib\dglib.obj /OUT:build\lib.win-amd64-3.6\pydggrid.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\Personal\Lab\DGGRID\pydggrid-master\src\pydggrid.cp36-win_amd64.lib
Creating library build\temp.win-amd64-3.6\Release\Personal\Lab\DGGRID\pydggrid-master\src\pydggrid.cp36-win_amd64.lib and object build\temp.win-amd64-3.6\Release\Personal\Lab\DGGRID\pydggrid-master\src\pydggrid.cp36-win_amd64.exp
gridgen.obj : error LNK2001: unresolved external symbol GDALAllRegister
quadclip.obj : error LNK2001: unresolved external symbol CSLPartialFindString
DgOutShapefile.obj : error LNK2001: unresolved external symbol DBFWriteStringAttribute
build\lib.win-amd64-3.6\pydggrid.cp36-win_amd64.pyd : fatal error LNK1120: 215 unresolved externals
error: command 'd:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.22.27905\\bin\\HostX86\\x64\\link.exe' failed with exit status 1120

ext_modules = [
    Extension(
        include_dirs=[],
        # extra_link_args=[r'"/LIBPATH:E:\Personal\SideWorks\vcpkg\installed\x86-windows\lib"'],
        libraries =['gdal','geos','geos_c'],
        library_dirs =['E:\Personal\SideWorks\vcpkg\installed\x86-windows\lib'],
        language='c++'
    ),
]

I think this is because of my wrong linking method. I found that there is a CMAKE function named find_gdal (https://github.com/Kitware/CMake/blob/master/Modules/FindGDAL.cmake) which sets some environment variables. however I am using python's setup.py to build the library so I don't access to this command. Is there any way to link this library manually?

Metadata

Metadata

Assignees

Labels

category:port-bugThe issue is with a library, which is something the port should already support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions