For those interested, I succesfully compiled libcflie and the examples in windows with some help of Luminita from this forum. Steps are roughly as follows:
- Install MinGW:
Download and make sure the system PATH variable is up to date after installing.
- Install cmake-gui:
Download (Installs with GUI automatically)
- Downloadlibcflie source of course:
Here
- Extract libcflie source to C:\libcflie-master (Or any other folder, but I'll use C:\ as my root folder)
- Download libusb-1.0:
Download
- Extract libusb to C:\libusb-1.0
- Download GLFW (Version <3.0!!):
Download
- Extract to C:\glfw-2.7.9
- First compile glfw:
* In a command prompt cd to glfw root folder and do: mingw32-make win32-mingw
This should automatically build the .dll which should now be in: 'C:\glfw-2.7.9\lib\win32\glfw.dll'
- libusb-1.0 comes precompiled already. Its either in 'C:\libusb-1.0\MinGW32\dll' or 'C:\libusb-1.0\MinGW64\dll', choose the one which corresponds to your architecture.
- If you want these libraries to be available system-wide copy both .dll's to 'C:\Windows\System32'. Otherwise make sure they are placed in the same folder as your executables or update the PATH variable.
- Copy the necessary header files:
* copy the folder 'GL' from 'C:\glfw-2.7.9\include' to 'C:\libcflie-master\include'
* copy the folder 'libusb-1.0' from 'C:\libusb-1.0\include' to 'C:\libcflie-master\include'
- Fix some things in the libcflie code:
* In CCrazyflie.cpp (\src\cflie\) on line 226: clock_gettime() does not work on windows. Replace this code:
Code: Select all
struct timespec tsTime;
clock_gettime(CLOCK_MONOTONIC, &tsTime);
return tsTime.tv_sec + double(tsTime.tv_nsec) / NSEC_PER_SEC;
with this code:
Code: Select all
struct timeval tsTime;
win_clockgettime(CLOCK_MONOTONIC, &tsTime);
return tsTime.tv_sec + double(tsTime.tv_usec) / 1000000.0;
* On line 28 add: '#include "time.h"'
* Underneath '#include <cflie/CCrazyflie.h>' add this custom code for the windows gettime function (thanks to Luminita

)
Code: Select all
LARGE_INTEGER getFILETIMEoffset()
{
SYSTEMTIME s;
FILETIME f;
LARGE_INTEGER t;
s.wYear = 1970;
s.wMonth = 1;
s.wDay = 1;
s.wHour = 0;
s.wMinute = 0;
s.wSecond = 0;
s.wMilliseconds = 0;
SystemTimeToFileTime(&s, &f);
t.QuadPart = f.dwHighDateTime;
t.QuadPart <<= 32;
t.QuadPart |= f.dwLowDateTime;
return (t);
}
int win_clockgettime(int X, struct timeval *tv)
{
LARGE_INTEGER t;
FILETIME f;
double microseconds;
static LARGE_INTEGER offset;
static double frequencyToMicroseconds;
static int initialized = 0;
static BOOL usePerformanceCounter = 0;
if (!initialized) {
LARGE_INTEGER performanceFrequency;
initialized = 1;
usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency);
if (usePerformanceCounter) {
QueryPerformanceCounter(&offset);
frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.;
} else {
offset = getFILETIMEoffset();
frequencyToMicroseconds = 10.;
}
}
if (usePerformanceCounter) QueryPerformanceCounter(&t);
else {
GetSystemTimeAsFileTime(&f);
t.QuadPart = f.dwHighDateTime;
t.QuadPart <<= 32;
t.QuadPart |= f.dwLowDateTime;
}
t.QuadPart -= offset.QuadPart;
microseconds = (double)t.QuadPart / frequencyToMicroseconds;
t.QuadPart = microseconds;
tv->tv_sec = t.QuadPart / 1000000;
tv->tv_usec = t.QuadPart % 1000000;
return (0);
}
double currentTime()
{
struct timeval tvTime;
win_clockgettime(0, &tvTime);
return tvTime.tv_sec + double(tvTime.tv_usec) * 1000 / NSEC_PER_SEC;
}
* In replugging.cpp (\src\examples\): remove or comment out lines 62-64:
Code: Select all
struct timespec tmWait;
tmWait.tv_sec = 0;
tmWait.tv_nsec = 500000000;
* on line 75 replace
with:
- Fix libraries in the makefile:
* open CMakeLists.txt from 'C:\libcflie-master' in a text editor
* on line 46 replace 'GL GLU' with 'opengl32' to replace the opengl library with the windows one
- Open cmake-gui and setup things:
* in the field 'Where is the source code' set: 'C:\libcflie-master'
* in the field 'Where to build the binaries' set: 'C:\libcflie-master\build' (Create this build folder yourself first!)
* Click 'Configure'
* Choose 'MinGW Makefiles' and 'Use default native compilers'
* Neglect the error
* In the 'GLFW_LIB' field put: 'C:\glfw-2.7.9\lib\win32\glfw.dll'
* Click configure again and neglect the error
* In the 'USB_LIB' field put: 'C:\libusb-1.0\MinGW64\dll\libusb-1.0.dll' (or the MinGW32 folder on a 32 bits system)
* Click configure again and then generate.
* close cmake-gui
- Compile everything:
* open a command prompt and cd to the folder: 'C:\libcflie-master\build'
* do: mingw32-make
That should be it!
The static library is built in: 'C:\libcflie-master\lib' and the example executables are built in: 'C:\libcflie-master\bin'
Hopefully this little tut is useful to someone. It probably is not the neatest way of compiling libcflie on windows, so feel free to comment on this! I succeeded in compiling it on both Win7 64bits and Win10 64bits using MinGW. I didn't try VC++ so if anyone did feel free to add instructions for this.