GDAL Not Linking - c++

I'm trying to get my program running on Windows. It depends on GDAL, a library for loading GIS data. It compiles and links fine on both Linux and macOS. I'm using CMake with MinGW and I'm running into linking errors like this:
undefined reference to `GDALRasterBand::RasterIO(GDALRWFlag, int, int, int, int, void*, int, int, GDALDataType, long, long, GDALRasterIOExtraArg*)'
CMakeFiles\Routes.dir/objects.a(elevation.cpp.obj): In function `ZN13ElevationData9calcStatsEv':
C:/Users/Logan/Documents/Routes/src/elevation/elevation.cpp:138: undefined reference to `GDALDataset::GetRasterXSize()'
C:/Users/Logan/Documents/Routes/src/elevation/elevation.cpp:139: undefined reference to `GDALDataset::GetRasterYSize()'
CMakeFiles\Routes.dir/objects.a(elevation.cpp.obj): In function `ZN13ElevationData17createOpenCLImageEv':
C:/Users/Logan/Documents/Routes/src/elevation/elevation.cpp:206: undefined reference to `GDALRasterBand::RasterIO(GDALRWFlag, int, int, int, int, void*, int, int, GDALDataType, long, long, GDALRasterIOExtraArg*)'
I compiled GDAL with VS2017 and I've verified that it is installed where I am specifying in my CMake File. Here is the relevant portions of the CMakeLists.txt:
IF (WIN32)
message(STATUS "Compiling for Windows")
set(GDAL_LIBRARY "C:/warmerda/bld/lib/gdal_i.lib")
set(GDAL_INCLUDE_DIR "C:/warmerda/bld/include/")
find_package(OpenCL REQUIRED)
include_directories(${OpenCL_INCLUDE_DIRS})
ELSE()
...
message(STATUS ${GDAL_LIBRARY})
target_link_libraries(Routes ${GDAL_LIBRARY} ${OpenCL_LIBRARIES})
I almost never do development on Windows so I'm kind of stuck. I've tried linking against the dll as well with no avail. Any ideas?

Apparently you're attempting to link a library you compiled with VC++ with object
files that you're compiling with GCC (MinGW). That doesn't work.
GCC and VC++ have different and incompatible ABIs,
and in particular different name mangling protocols.
Hence the mangled function names emitted by MinGW in your object code will
not match any exported by your VC++ compiled library. You will need to
build the GDAL library with MinGW.

Thanks #MikeKinghan! I had been pulling my hair out for couple of days! Your answer clicked right away. For those who want to have no headache with the libraries, just use MSYS2 (msys2.org). Then using pacman in the msys2 command prompt, get the MingW (pacman -S mingw-w64-x86_64-gcc) and GDAL (pacman -S mingw-w64-x86_64-gdal).

Related

undefined Reference to "_ZNSt5__padIcSt11char_traitsIcEE6_S_padERSt8ios_basecPcPKcllb" symbol is not exported from libstdc++.a(libstdc++.so.6)

I am able to build my code successfully but getting following error while trying to run it. I am on AIX7.1 using GCC4.8.5.
0509-130 Symbol resolution failed for libadobelinguistic.a because:
0509-136 Symbol _ZNSt5__padIcSt11char_traitsIcEE6_S_padERSt8ios_basecPcPKcllb (number 94) is not exported from
dependent module /user/unicore/rs6000aix/compiler/gcc4.8.5/aix6.1/lib/libstdc++.a(libstdc++.so.6).
0509-022 Cannot load module .
0509-026 System error: Cannot run a file that does not have a valid format.
0509-192 Examine .loader section symbols with the
'dump -Tv' command."}
As suggested at few places I used -Wl,--no-undefined flag to fail the project at compilation time. but compilation is not failing.
demangled function:
std::__pad<char, std::char_traits<char> >::_S_pad(std::ios_base&, char, char*, char const*, long, long, bool)
I am unable to find reference to this function.
Moreover as suggested at few places In case of such errors you need to set LIBPATH variable in case of AIX. I have libpath variable set to
LIBPATH=/user/unicore/rs6000aix/compiler/gcc4.8.5/aix6.1/lib:/opt/freeware/lib:/user/unicore/rs6000aix/compiler/gcc4.8.5/aix6.1/lib/gcc/powerpc-ibm-aix6.1.0.0/4.8.5:/opt/freeware/lib/pthread/ppc64
still it is not working.
I found a reference to it https://sourceforge.net/p/slo/feature-requests/4/. but it is not helpful.
Edit: seems like libstdc++ is causing issue on the AIX7.1. we have system libstdc++ and libstdc++ of gcc4.8.5. when I link to system libstdc++ gdb runs successfully but my program fails but when i set path to libstdc++ in gcc4.8.5. GDB doesn't run but my executable runs. seems like system libstdc++ and gcc4.8.5 libstdc++ are not compatible.
Issue was with libstdc++. By default LIBPATH was set to opt/freeware/lib where libstdc++ was available. While compiling my source was getting linked to libstdc++ available at the 'opt/freeware/lib' location. where as at run time it was looking for 'libstdc++' available in the gcc4.8.5. causing the issue.
setting LIBPATH to gcc lib directory solved the issue.

Linking with BLAS OS X

I am currently trying to compile a program using a library that I'm not very familiar with. When I run the compiler, I get the following output/error:
Undefined symbols for architecture x86_64:
"_cblas_ddot", referenced from:
shark::LDA::train(shark::LinearClassifier<shark::blas::vector<double> >&, shark::LabeledData<shark::blas::vector<double>, unsigned int> const&) in libshark.a(LDA.cpp.o)
shark::LDA::train(shark::LinearClassifier<shark::blas::vector<double> >&, shark::WeightedLabeledData<shark::blas::vector<double>, unsigned int> const&) in libshark.a(LDA.cpp.o)
My current idea is that this is from missing BLAS library, which I just downloaded and compiled (from fortran code?).
The command-line arg for compiling looks like thsi
g++ -o example -I/to/boost/include -I/to/shark/include -L/to/boost/lib -L/to/shark/lib -L/to/BLAS -lshark -lblas -l(boost_flags)
In /to/BLAS have a libblas.a, and I ran nm libblas.a which gives a line
libblas.a(ddot.o):
00000000000001c0 s EH_frame1
0000000000000000 T _ddot_
Without being too secure abut this, I assume that this means that the library does have the symbol, but without the _cblas_ prefix.
What can I do from this point? Can I change the symbols name? Or do I need to link this library with something else?
I use OS X Mavericks
Thanks in advance : )
OS X ships with BLAS (including cblas) already installed (it's part of the Accelerate.framework). There's no need to download and build your own. Just link with -lcblas.
Solution was as suggested by Logicrat, that I needed other files, I downloaded te source code from here and build it with cmake/make very seamless. Linking with the libraries that came from this resolved the issue.

Undefined reference to gfortran_runtime_error

I would like to run a model is written Fortran90 under Ubuntu 14.04. I use gfortran 95 compiler (gfortran 4:4.8.2-1ubuntu6). The required netCDF libraries (netCDF C and Fortran netCDF) are installed as suggested in: http://www.unidata.ucar.edu/software/netcdf/docs/. The netcdf is built as shared library so libnetcdf.so and libnetcff.so files there are in the library directory. The libgfortran3 4.8.2-19ubuntu1 is installed for GNU fortran application linked against the shared library.
The LDFLAGS is set in the compiler_options.inc file by the following way:
INCDF=-I$(NCPATH)/include
LNCDF=-L$(NCPATH)/lib -lnetcdff -lnetcdf
LDFLAGS=$(INCDF) $(LNCDF)
When I compile the model I get the following messages:
/home/Beata/kid_a_setup/src/test_cases_2d.f90:1446: undefined reference to `_gfortran_runtime_error_at
Could someone explain me what causes the error and how I can fix it?
undefined reference to _gfortran_runtime_error_at means that the libgfortran library has not been found.
Either your system is misconfigured (can you compile, link and run a "Hello, world" program using gfortran?), or you are using the gcc command for linking instead of gfortran for linking. gcc does not know about the libgfortran library, where _gfortran_runtime_error_at is defined.

Linking with gmock libs generated using GCC 3.4.6 (libstdc++.so.6.0.13) gives "undefined reference to... #GLIBCXX_3.4.9" errors

Linking with gmock(1.4+svn281) libs generated on a Linux machine "A", having GCC 3.4.6 using libstdc++.so.6.0.13 gives me the following linking error:
libgmock.so: undefined reference to `std::basic_ostream >& std::__ostream_insert >(std::basic_ostream >&, char const*, long)#GLIBCXX_3.4.9'
...
I tried also with the latest gmock release version and also got the undefined reference to... #GLIBCXX_3.4.9 errors (this time with other symbols).
Building gmock using the same build procedure, however on another machine "B" (retired machine now, but previously used to generate the older binaries) I was able to link successfully. The machine uses GCC 3.4.6, with a different libstdc++ version: libstdc++.so.6.0.3.
Grepping on libstdc++.so.6.0.13 for GLIBCXX_3.4.9 shows that it contains such symbol patterns:
_ZNSt13basic_ostreamIwSt1##GLIBCXX_3.4.9 (referencing GLIBCXX_3.4.9, hence the error). I verified that this is not the case for libstdc++.so.6.0.3
To understand the linking error and what are my options, I read about libstdc++ and glibcxx to get some perspective, but couldn't conclude the relation between the libs: Does libstdc++ need glibcxx or is it the other way around (the error message makes it seem that the problem is: at glibcxx there is an undefined reference to a symbol in libstdc++)?
Does libstdc++ implicitly link with glibcxx (knowing that libstdc++ can reference multiple glibcxx versions at a time)?
I don't want to go back to the old machine to build gmock whenever I want to update the libs, am I constrained to building gmock with specific libstdc++ versions that work?
Appreciate any help on the issue
EDIT:
I built gmock libs on machine "A" and specified the version of libstdc++: libstdc++.so.6.0.3 and got the same errors as before, but this time without the #GLIBCXX_3.4.9 appended at the end of the symbol:
libgmock.so: undefined reference to `std::basic_ostream >& std::__ostream_insert >(std::basic_ostream >&, char const*, long)'
...
I also verified that libstdc++.so.6.0.3 was actually taken, by launching the command: "readelf -a libgmock.so" and verifying that GLIBCXX_3.4.9 was not referenced.
To understand the linking error and what are my options, I read about libstdc++ and glibcxx to get some perspective, but couldn't conclude the relation between the libs: Does libstdc++ need glibcxx
There is no such thing as glibcxx library. The libstdc++.so uses GNU symbol versioning, and uses GLIBCXX symbol prefix. The whole GLIBCXX is implementation detail of libstdc++ itself.
Your actual problem, and possible solutions, is explained here.
Effectively, you can not expect a binary linked on a newer Linux system to work on an older one.

Adding Boost.Log to boost libraries using CMake

I am trying to add Boost.Log to the Boost libraries using CMake, but I am having trouble when trying to link into my program.
I've added a wrapper around the Boost.Log and generated a shared library called libcls_utils.so. The Boost libraries (along with Boost.Log) appear to be built and generate all the .so files properly in the correct location, and so does libcls_utils.so.
When I try to link my file, I get the following error:
/media/data/workspace/mdxdev/tmp/staging/i686-mv-linux/usr/lib/libcls_utils.so: undefined reference to `boost::log_mt_posix::sinks::basic_text_file_backend::construct(boost::fil‌​esystem2::basic_path, std::allocator >, boost::filesystem2::path_traits> const&, std::_Ios_Openmode, unsigned long long, boost::function0 const&, bool)
As far as I can tell, I'm linking against all the correct libraries. Has anyone tried this before successfully? What am I doing wrong?
I am using CMake 2.8.8, Boost-1.49.0 and Boost.Log from the svn trunk.
You might need to define BOOST_LOG_DYN_LINK:
g++ -DBOOST_LOG_DYN_LINK blog.cpp -lboost_log -lpthread