Undefined reference to static const class members (MSVC 2013 and shared library)

I'm trying to compile the following (main.cpp):

#include "H5Cpp.h"

using namespace H5;

int main (void)
{
     H5File file("test.h5", H5F_ACC_TRUNC);
}

The H5File constructor used here has the following signature:

H5File(const char* name, unsigned int flags, const FileCreatPropList&
create_plist = FileCreatPropList::DEFAULT, const FileAccPropList&
access_plist = FileAccPropList::DEFAULT);

...so it as two additional default parameters. I get undefined
reference when the linker is trying to resolve those:

main.obj : error LNK2019: unresolved external symbol "public: static
class H5::FileAccPropList const & const H5::FileAccPropList::DEFAULT"
(?DEFAULT@FileAccPropList@H5@@2ABV12@B) referenced in function _main

main.obj : error LNK2019: unresolved external symbol "public: static
class H5::FileCreatPropList const & const
H5::FileCreatPropList::DEFAULT"
(?DEFAULT@FileCreatPropList@H5@@2ABV12@B) referenced in function

I'm using QtCreator since I'm going to use the library in a Qt
application. The .pro file for QtCreator is as follows:

TARGET = hdf5_test
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += "C:/Program Files (x86)/HDF_Group/HDF5/1.8.16/include"
LIBS += -L"C:/Program Files (x86)/HDF_Group/HDF5/1.8.16/lib/" -lhdf5 -lhdf5_cpp

- I'm linking against the shared library version
- I have no preprocessor directives defined
- I'm using the contents of this installer: HDF5-1.8.16-win32.msi

Can someone provide me with a working C++ example for this latest library?

Since I'm not using CMake, what is useful for me in an example is:
code, include path, library path, preprocessor defines and possibly
compiler switcher.

Is one option to use the static versions instead? If so how can I
debug my application if only release builds are available? (Cannot mix
release and debug binaries).

Hi Stig,

You could build your own debug version from the source code:

https://www.hdfgroup.org/HDF5/release/obtain5.html#obtain

​Binh-Minh

···

________________________________________
From: Hdf-forum <hdf-forum-bounces@lists.hdfgroup.org> on behalf of Stig Hornang <shornang@gmail.com>
Sent: Thursday, January 14, 2016 9:11 AM
To: hdf-forum@lists.hdfgroup.org
Subject: [Hdf-forum] Undefined reference to static const class members (MSVC 2013 and shared library)

I'm trying to compile the following (main.cpp):

#include "H5Cpp.h"

using namespace H5;

int main (void)
{
     H5File file("test.h5", H5F_ACC_TRUNC);
}

The H5File constructor used here has the following signature:

H5File(const char* name, unsigned int flags, const FileCreatPropList&
create_plist = FileCreatPropList::DEFAULT, const FileAccPropList&
access_plist = FileAccPropList::DEFAULT);

...so it as two additional default parameters. I get undefined
reference when the linker is trying to resolve those:

main.obj : error LNK2019: unresolved external symbol "public: static
class H5::FileAccPropList const & const H5::FileAccPropList::DEFAULT"
(?DEFAULT@FileAccPropList@H5@@2ABV12@B) referenced in function _main

main.obj : error LNK2019: unresolved external symbol "public: static
class H5::FileCreatPropList const & const
H5::FileCreatPropList::DEFAULT"
(?DEFAULT@FileCreatPropList@H5@@2ABV12@B) referenced in function

I'm using QtCreator since I'm going to use the library in a Qt
application. The .pro file for QtCreator is as follows:

TARGET = hdf5_test
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += "C:/Program Files (x86)/HDF_Group/HDF5/1.8.16/include"
LIBS += -L"C:/Program Files (x86)/HDF_Group/HDF5/1.8.16/lib/" -lhdf5 -lhdf5_cpp

- I'm linking against the shared library version
- I have no preprocessor directives defined
- I'm using the contents of this installer: HDF5-1.8.16-win32.msi

Can someone provide me with a working C++ example for this latest library?

Since I'm not using CMake, what is useful for me in an example is:
code, include path, library path, preprocessor defines and possibly
compiler switcher.

Is one option to use the static versions instead? If so how can I
debug my application if only release builds are available? (Cannot mix
release and debug binaries).

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

In non-CMake uses, the "H5_BUILT_AS_DYNAMIC_LIB" define must be declared.
A Note about this should be in INSTALL_WINDOWS.txt or USING_HDF5_VS.txt -
HOWEVER this note might have been omitted in the last release docs, it is in
the next release. This define is automatically handled using CMake.

Allen

···

On Thursday, January 14, 2016 03:11:53 PM Stig Hornang wrote:

I'm trying to compile the following (main.cpp):

#include "H5Cpp.h"

using namespace H5;

int main (void)
{
     H5File file("test.h5", H5F_ACC_TRUNC);
}

The H5File constructor used here has the following signature:

H5File(const char* name, unsigned int flags, const FileCreatPropList&
create_plist = FileCreatPropList::DEFAULT, const FileAccPropList&
access_plist = FileAccPropList::DEFAULT);

...so it as two additional default parameters. I get undefined
reference when the linker is trying to resolve those:

main.obj : error LNK2019: unresolved external symbol "public: static
class H5::FileAccPropList const & const H5::FileAccPropList::DEFAULT"
(?DEFAULT@FileAccPropList@H5@@2ABV12@B) referenced in function _main

main.obj : error LNK2019: unresolved external symbol "public: static
class H5::FileCreatPropList const & const
H5::FileCreatPropList::DEFAULT"
(?DEFAULT@FileCreatPropList@H5@@2ABV12@B) referenced in function

I'm using QtCreator since I'm going to use the library in a Qt
application. The .pro file for QtCreator is as follows:

TARGET = hdf5_test
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += "C:/Program Files (x86)/HDF_Group/HDF5/1.8.16/include"
LIBS += -L"C:/Program Files (x86)/HDF_Group/HDF5/1.8.16/lib/" -lhdf5
-lhdf5_cpp

- I'm linking against the shared library version
- I have no preprocessor directives defined
- I'm using the contents of this installer: HDF5-1.8.16-win32.msi

Can someone provide me with a working C++ example for this latest library?

Since I'm not using CMake, what is useful for me in an example is:
code, include path, library path, preprocessor defines and possibly
compiler switcher.

Is one option to use the static versions instead? If so how can I
debug my application if only release builds are available? (Cannot mix
release and debug binaries).

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

The H5_BUILT_AS_DYNAMIC_LIB could probably be removed. It was there before the current HDF5Config.cmake files were around and was needed in order to try to figure out what files to look for when using HDF5 in other CMake projects. Now with the HDF5Config.cmake files being generated by the HDF5 project itself and used by other CMake projects it may be possible to remove the variable.

···

--
Mike Jackson [mike.jackson@bluequartz.net]

On Jan 19, 2016, at 9:43 AM, Allen Byrne <byrn@hdfgroup.org> wrote:

In non-CMake uses, the "H5_BUILT_AS_DYNAMIC_LIB" define must be declared.
A Note about this should be in INSTALL_WINDOWS.txt or USING_HDF5_VS.txt -
HOWEVER this note might have been omitted in the last release docs, it is in
the next release. This define is automatically handled using CMake.

Allen

On Thursday, January 14, 2016 03:11:53 PM Stig Hornang wrote:

I'm trying to compile the following (main.cpp):

#include "H5Cpp.h"

using namespace H5;

int main (void)
{
    H5File file("test.h5", H5F_ACC_TRUNC);
}

The H5File constructor used here has the following signature:

H5File(const char* name, unsigned int flags, const FileCreatPropList&
create_plist = FileCreatPropList::DEFAULT, const FileAccPropList&
access_plist = FileAccPropList::DEFAULT);

...so it as two additional default parameters. I get undefined
reference when the linker is trying to resolve those:

main.obj : error LNK2019: unresolved external symbol "public: static
class H5::FileAccPropList const & const H5::FileAccPropList::DEFAULT"
(?DEFAULT@FileAccPropList@H5@@2ABV12@B) referenced in function _main

main.obj : error LNK2019: unresolved external symbol "public: static
class H5::FileCreatPropList const & const
H5::FileCreatPropList::DEFAULT"
(?DEFAULT@FileCreatPropList@H5@@2ABV12@B) referenced in function

I'm using QtCreator since I'm going to use the library in a Qt
application. The .pro file for QtCreator is as follows:

TARGET = hdf5_test
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += "C:/Program Files (x86)/HDF_Group/HDF5/1.8.16/include"
LIBS += -L"C:/Program Files (x86)/HDF_Group/HDF5/1.8.16/lib/" -lhdf5
-lhdf5_cpp

- I'm linking against the shared library version
- I have no preprocessor directives defined
- I'm using the contents of this installer: HDF5-1.8.16-win32.msi

Can someone provide me with a working C++ example for this latest library?

Since I'm not using CMake, what is useful for me in an example is:
code, include path, library path, preprocessor defines and possibly
compiler switcher.

Is one option to use the static versions instead? If so how can I
debug my application if only release builds are available? (Cannot mix
release and debug binaries).

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Okay. I will need to build my own HDF binary.

Still, it would be great that the pre-built version works correctly in
a non CMake build enviroment.

Either there is a bug in the binary or I can't find the missing
information to make it work (e.g. a preprocessor DEFINE).

···

--
Regards,
Stig

Hi Stig,

BTW, have you tried switching the order of the libraries, i.e., instead of

LIBS += -L"C:/Program Files (x86)/HDF_Group/HDF5/1.8.16/lib/" -lhdf5 -lhdf5_cpp

try this:
LIBS += -L"C:/Program Files (x86)/HDF_Group/HDF5/1.8.16/lib/" -lhdf5_cpp -lhdf5

​Binh-Minh

···

________________________________________
From: Hdf-forum <hdf-forum-bounces@lists.hdfgroup.org> on behalf of Stig Hornang <shornang@gmail.com>
Sent: Tuesday, January 19, 2016 3:20 AM
To: hdf-forum@lists.hdfgroup.org
Subject: Re: [Hdf-forum] Undefined reference to static const class

Okay. I will need to build my own HDF binary.

Still, it would be great that the pre-built version works correctly in
a non CMake build enviroment.

Either there is a bug in the binary or I can't find the missing
information to make it work (e.g. a preprocessor DEFINE).

--
Regards,
Stig

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5