Making fmt/chrono.h work in a cuda runtime project

empeirikos 0 Reputation points
2025-02-09T13:00:30.7733333+00:00

To avoid creating my own errors I copied the following code from fmt.

My code only has the cuda runtime headers (which are included automatically whenever a cuda runtime project is created).

#include "cuda_runtime.h"
#include "device_launch_parameters.h"

//#include <stdio.h>
#include <fmt/chrono.h>

int main() {
	auto now = std::chrono::system_clock::now();
	fmt::print("{}\n", now);
	fmt::print("{:%S}\n", now);
	fmt::print("{:%d/%m}\n", now);

	using tp = std::chrono::time_point<
		std::chrono::system_clock, std::chrono::seconds>;
	fmt::print("--------------\n");
	fmt::print("{:%S}\n", tp(std::chrono::seconds(47)));
	using namespace std::chrono_literals;
	fmt::print("{}\n", tp(32s));
	fmt::print("{:%S}\n", tp(32s));
}

I have followed various suggestions (include /utf-8 flag in project CUDA C/C++>Command Line>Additional Options , save .cu file using UTF-8 encoding) but none of them works. It should be fairly easy making this simple code works but it seems cuda runtime makes things much harder. By the way if I create an Empty Project and then build it using the utf-8 flag it works fine.

Developer technologies C++
Developer technologies Visual Studio Other
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.