FreeFem/FreeFem-sources

Failure or success in windows developer instructions for adding built-in functionalities to FreeFEM++?

Opened this issue · 0 comments

On Windows, I wanted to add a PackSixDoubles method to FreeFEM++ with the following c++ code of the file combine_six_float.cpp:

#include <iostream>
#include <cstdint>
#include <cstring>
#include "AFunction.hpp"
#include "AFunction_ext.hpp"
#include "ff++.hpp"

using namespace std;

// Constants for packing/unpacking
const int BITS_PER_DOUBLE = 10; // Number of bits for each double (reduced precision)
const int TOTAL_BITS = 64;
const int NUM_DOUBLES = 6;

// Function to reduce the precision of a double
unsigned long long reducePrecision(double value)
{
	// Shift and truncate the double (this is just a placeholder for actual precision reduction)
	unsigned long long intValue = static_cast<unsigned long long>(value * (1 << BITS_PER_DOUBLE));
	return intValue;
}

// Function to pack 6 doubles into one double (changed signature to pass by value)
double PackSixDoubles(const double &d1, const double &d2, const double &d3, const double &d4, const double &d5, const double &d6)
{
	// Reduced precision for each double
	unsigned long long r1 = reducePrecision(d1);
	unsigned long long r2 = reducePrecision(d2);
	unsigned long long r3 = reducePrecision(d3);
	unsigned long long r4 = reducePrecision(d4);
	unsigned long long r5 = reducePrecision(d5);
	unsigned long long r6 = reducePrecision(d6);

	// Combine them using bitshift operations
	unsigned long long packedValue = (r1 << (5 * BITS_PER_DOUBLE)) |
																	 (r2 << (4 * BITS_PER_DOUBLE)) |
																	 (r3 << (3 * BITS_PER_DOUBLE)) |
																	 (r4 << (2 * BITS_PER_DOUBLE)) |
																	 (r5 << (1 * BITS_PER_DOUBLE)) |
																	 r6;

	// Cast to double
	return *reinterpret_cast<double *>(&packedValue);
}

static void init()
{
	// Use OneOperator6_ for the function with six double arguments
	Global.Add("PackSixDoubles", "(", new OneOperator6_<double, double>(PackSixDoubles));
}

LOADFUNC(init);

no errors seem to be indicated with intellisense for the c++ code, so with $FF_FOLDER set to the FreeFEM++ folder I proceed in MINGW64 / MSYS2:

  1. ff-c++ -cygwin ./combine_six_float.cpp (OK)
  2. g++ -c -g -I "$FF_FOLDER/include/ -Iinclude ./combine_six_float.cpp (OK)
  3. g++ -shared -g ./combine_six_float.o -o ./combine_six_float.dll -L $FF_FOLDER/include/ -L $FF_FOLDER/include/ (FAILED)

Since step 1 seems to already produce a .o and .dll file that I can use in FreeFEM++, are steps 2 and 3 (which fails) even needed?
They are mentioned in the documentation...?