Error compiling HDF5 with MinGW and CMake - c

I'm trying to compile HDF5 with MinGW's gcc 4.8.1 and CMake. I followed the instructions in the INSTALL_CMake documentation for Windows and read everything that I found on Google but I still get the following errors:
In file included from c:\mingw32-xy\include\fcntl.h:37:0,
from C:\Users\jicervan.NDC\Downloads\hdf5-1.8.13\hdf5-1.8.13\src\H5private.h:53,
from C:\Users\jicervan.NDC\Downloads\hdf5-1.8.13\hdf5-1.8.13\src\H5detect.c:57:
c:\mingw32-xy\include\io.h:301:1: error: unknown type name 'off64_t'
__CRT_INLINE off64_t lseek64 (int, off64_t, int);
^
c:\mingw32-xy\include\io.h:301:36: error: unknown type name 'off64_t'
__CRT_INLINE off64_t lseek64 (int, off64_t, int);
^
c:\mingw32-xy\include\io.h:302:1: error: unknown type name 'off64_t'
__CRT_INLINE off64_t lseek64 (int fd, off64_t offset, int whence) {
^
c:\mingw32-xy\include\io.h:302:39: error: unknown type name 'off64_t'
__CRT_INLINE off64_t lseek64 (int fd, off64_t offset, int whence) {
^
In file included from C:\Users\jicervan.NDC\Downloads\hdf5-1.8.13\hdf5-1.8.13\src\H5private.h:70:0,
from C:\Users\jicervan.NDC\Downloads\hdf5-1.8.13\hdf5-1.8.13\src\H5detect.c:57:
c:\mingw32-xy\include\unistd.h:65:20: error: unknown type name 'off_t'
int ftruncate(int, off_t);
The errors and warnings go on and on with a long list of warnings and undefines. Does anybody has any suggestions on how to solve this problem? Are there any other alternatives like using the Visual Studio binaries with MinGW maybe?

I finally got it working. My first attempt was to use configure and make according to the documentation in the /release_docs/INSTALL_MinGW.txt file, but it didn't work. I ended up using CMake. For documentation purposes, here's the procedure that I followed:
OPERATING SYSTEM: Windows 8.1 pro
COMPILER: CMake + MinGW gcc version 4.8.1
HDF5 VERSION: 1.8.13
STEPS:
Uncompress the hdf5-1.8.13.zip file.
Download CMake, and run the GUI.
Set the source folder to <hdf5-location>/hdf5-1.8.13 and the build folder to the folder where you want to place your Makefile.
Click on Configure, and a pop-up window will appear. Choose the MinGW Makefiles option as the generator for your project, and select the Use default native compilers option.
Once the list is populated with options, leave the default checkboxes selected, and also select BUILD_SHARED_LIBRARIES. Now the fun begins; compiling.
Locate the file H5pubconfig.h file in your HDF5 build folder and append the following lines:
// Define Windows 32
#ifndef H5_HAVE_WIN32_API
#ifdef WIN32 /* defined for all windows systems */
#define H5_HAVE_WIN32_API 1
#endif
#endif
// Define MinGW
#ifndef H5_HAVE_MINGW
#ifdef __MINGW32__ /*defined for all MinGW compilers */
#define H5_HAVE_MINGW 1
#endif
#endif
// Redefine _In_ and _Out_ to empty values
#define _In_
#define _Out_
// Redefine off_t and off64_t to match io.h and unistd.h
#define off_t _off_t
#define off64_t _off64_t
On the file io.hlocated in <MyFolder>/MinGW32/include/ change every instance of off64_t to _off64_t.
On the file unistd.hlocated in <MyFolder>/MinGW32/include/ change every instance of off_t to _off_t.
On the MinGW/MSYS command prompt, change directory to the location of your HDF5 Makefile (set on step 3).
Type the command Make and verify that it's compiled correctly.
Don't forget to include the flags -I/<your-HDF5-build-folder>/include/, -L/<your-HDF5-build-folder>/bin/, and -lhdf5 when you compile. Happy coding.

Related

STM32 Cmake STM32Workbench project

I am trying to write a CMakeLists.txt file for my STM32 project. I am using cmake files from this repo: https://github.com/ObKo/stm32-cmake. Building from command line works fine. I am doing it in that way:
cmake -C "..\STM32F207ZCTx_config.cmake" -DCMAKE_BUILD_TYPE=DEBUG -G "Eclipse CDT4 - Unix Makefiles" ..
make.exe -j4
In cache file I have some variables set:
set(CMAKE_MAKE_PROGRAM "D:/STM32Workbench/plugins/fr.ac6.mcu.externaltools.arm-none.win32_1.16.0.201807130628/tools/make/make.exe" CACHE STRING "stm32 make")
set(CMAKE_TOOLCHAIN_FILE "stm32-cmake/gcc_stm32.cmake" CACHE STRING "stm32 toolchain")
set(TOOLCHAIN_PREFIX "D:/STM32Workbench/plugins/fr.ac6.mcu.externaltools.arm-none.win32_1.16.0.201807130628/tools/compiler" CACHE STRING "arm toolchain path")
When I import created project to STM32 Workbench it generates a lot of errors "unresolved external" regarding stdint.h types (e.g. uint8_t, int32_t).
After some debugging this problem I realized that there are missing some defines which are used by stdint.h header. I checked out the compiler with this command:
arm-none-eabi-gcc.exe -dM -E out.h
And got the list of defines in arm-none-eabi-gcc:
#define __UINTMAX_TYPE__ long long unsigned int
#define __INT_FAST16_TYPE__ int
#define __INT_FAST64_TYPE__ long long int
#define __INT_FAST32_TYPE__ int
#define __UINT_LEAST16_TYPE__ short unsigned int
#define __SIZE_TYPE__ unsigned int
#define __INT_LEAST16_TYPE__ short int
... and much more
These defines are needed by stdint.h to create correct uint8_t and other types.
I can add manually these defines to Eclipse project, but I am wondering if there is method to add these defines to Eclipse project automagically from CMake?
Any help will be appreciated.
Problem was in STM32Workbench. Sources were excluded from build and from indexer.
To fix it - right mouse click on source, Properties, C/C++ General, Preprocessor Include Paths, uncheck Exclude resource from build.
Now the indexer is able to find all sources and all "unresolved external" errors are gone!

Type __u64 could not be resolved / #if defined(__GNUC__)

I have C project for Android in Eclipse which is giving the error: Type '__u64' could not be resolved.
And __u64 appears as a greyed out type in the list beneath the relevant types.h file in the includes folder.
It seems that this problem is because the relevant type definition in the header file is preceded by #if defined (__GNUC__).
Fortunately the project builds OK (so is this an issue with Eclipse parser rather than Eclipse generator).
How do I get rid of the annoying error message?
EDIT . . .
Yes, the code is using __u64. It does what is required and the code works. My problem is not with the code. My problem is with Eclipse configuration.
I believe the Eclipse compiler (GNU C) sees the following (in types.h) -
#if defined(__GNUC__)
typedef typedeclaration
#endif
- passes the test, and accepts the declared data type.
But the Eclipse parser doesn't.
So how do I configure Eclipse so that the parser also passes the #if defined(__GNUC__) test and, in this instance, accepts __u64 as a legitimate data type.

VS 2013 error C1853 trying to build DLL (but not using precompiled headers set)

Hello I'm trying to build the simplest possible DLL in C using VS2013 community edition. I set "Not using Precompiled Headers" in the options (although somehow the project creation wizard seems to indicate that Using Precompiled Headers is
imposed because it's a greyed check option. Anyway I decide to turn it off uing the menus associated with the project properties anyway.) But I still get this error saying
Error 1 error C1853: 'Release\ExportDLLVars.pch' precompiled header file is from a previous version of the compiler, or the precompiled header is C++ and you are using it from C (or vice versa) D:\devt\CplusPlus\Tests\ExportDLLVars\ExportDLLVars\VarsSource.c 1 1 ExportDLLVars
I have created a default DLL project using the wizard and added the following two source files
#define NAME_SIZE 80
struct _Person
{
char name[NAME_SIZE];
int tel_nb;
int age;
};
#ifdef EXPORTDLLVARS_EXPORTS
#define DLL_VAR __declspec(dllexport)
#else
#define DLL_VAR __declspec(dllimport)
#endif
DLL_VAR int get_age();
DLL_VAR void set_age(int a);
DLL_VAR extern struct _Person ThePerson;
as the header file VarsSource.h and the C file is this:
#include "VarsSource.h"
DLL_VAR struct _Person ThePerson;
DLL_VAR int get_age(){ return ThePerson.age; }
DLL_VAR void set_age(int a){ ThePerson.age = a; }
The wizard creates a C++ project. Your C file cannot share precompiled headers with the C++ files generated by the wizard, which is what this part of the error means: or the precompiled header is C++ and you are using it from C.
Try the following:
Do a full Clean for all configurations.
Remove the stdafx.cpp file from the project.
Recheck the project settings and make sure that Configuration Properties / C/C++ / Precompiled Headers has them turned off both at the project level, and for each C/C++ file individually.

PostgreSQL: compile C function on Windows 8 64bit

I'm learning how to compile a C trigger to load on PostgreSQL
When compile the "trigf.c" (in the example at http://www.postgresql.org/docs/9.3/interactive/trigger-example.html), I get some issue related to int64 error (c.h header)
#ifdef HAVE_LONG_INT_64
/* Plain "long int" fits, use it */
#ifndef HAVE_INT64
typedef long int int64;
#endif
#ifndef HAVE_UINT64
typedef unsigned long int uint64;
#endif
#elif defined(HAVE_LONG_LONG_INT_64)
/* We have working support for "long long int", use that */
#ifndef HAVE_INT64
typedef long long int int64;
#endif
#ifndef HAVE_UINT64
typedef unsigned long long int uint64;
#endif
#else
/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */
#error must have a working 64-bit integer datatype
#endif
-> [Error] #error must have a working 64-bit integer datatype
I don't know how to solve that problem, because clearly that there is a working 64 bit integer datatype that I can use.
Edit: I installed pgsql from binary. The C compiler I used for compile the C function file is MinGW GCC 4.7.2. (Using the path of Dev-cpp mingw gcc).
The command line is :
gcc -fpic -c "D:\trigf.c"
At the first time, it showed an error that in c.h: not found libintl.h (no such file or directory). Then I download the Lib Intl - 0.14.4 (library for native language support). The installation create a folder: C:\Program Files (x86)\GnuWin32.
I edited the environment variable CPATH, added C:\Program Files (x86)\GnuWin32\include folder, which contained libintl.h.
I ran the command again, and I met with the above error.
Update: It turns out not to be too hard to build extensions stand-alone with MSVC on Windows. I wrote a blog post detailing the process today.
The usual way to build extensions on Windows is to do it inside a working PostgreSQL build tree.
See these instructions on the PostgreSQL wiki.
You might be able to do it using MinGW and PGXS using a suitable Makefile instead.
Just trying to compile a standalone .c file is unlikely to work as there are a variety of paths and preprocessor definitions required.
It doesn't help that the current PostgreSQL packages don't include headers for public dependencies, which is really rather frustrating. You can safely compile without ENABLE_NLS defined even if the target PostgreSQL was built with ENABLE_NLS, though, and in this case libintl.h won't be required.

MinGW GCC Not Recognizing MEMSTATUSEX?

I am using MinGW GCC compiler on Windows 7. I am trying to compile source that contains the following code:
MEMORYSTATUSEX mem_stat;
mem_stat.dwLength = sizeof(memstat);
BOOL success = GlobalMemoryStatusEx(mem_stat);
ram_ptr = &(mem_stat->ullAvailPhys);
As I'm sure you can guess, this code simply gets the available memory using the MEMORYSTATUSEX struct returned by GlobalMemoryStatusEx.
When I try to compile, I get this error:
error: unknown type name 'MEMORYSTATUSEX'
I looked in winbase.h (in the MinGW installation include folder) and guess what I found?
#if (_WIN32_WINNT >= 0x0500)
typedef struct _MEMORYSTATUSEX {
DWORD dwLength;
DWORD dwMemoryLoad;
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX,*LPMEMORYSTATUSEX;
#endif
So it's there. I'm guessing this has something to do with the precompiler if/endif, but I don't how to fix that....
Also what's even more bizzare is that if I use the MEMORYSTATUS struct instead, it works fine.
According to the MS docs, both have the same minimum client version requirement:
MEMORYSTATUSEX:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa366589%28v=vs.85%29.aspx
MEMORYSTATUS:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa366772%28v=vs.85%29.aspx
Is there some compiler flag I need to set? Or does anyone have any other solutions?
Thanks in advance for your help!
Before including Windows.h, add :
#define WINVER 0x0500
The header file windef.h says :
/*
* If you need Win32 API features newer the Win95 and WinNT then you must
* define WINVER before including windows.h or any other method of including
* the windef.h header.
*/
and then compile with the -std=c++11 flag like :
g++ -Wall -std=c++11 -c <yourFile>.cpp -o <yourFile>.o
Apparently you have to define _WIN32_WINNT yourself either as a compiler flag or definition statement in one of your header/source files for this particular function to work properly.
Adding the #define _WIN32_WINNT 0x0500 will allow the code to compile normally.

Resources