Closed shemeshg closed 1 week ago
I'm sorry it's been a bit since I looked at cpp2... can you help me create an MRE? Not sure what the intended workflow is
mkdir test
cd test
CMakeLists.txt
cmake_minimum_required(VERSION 3.23)
project(example)
include(FetchContent)
FetchContent_Declare(
cppfront
GIT_REPOSITORY https://github.com/modern-cmake/cppfront.git
GIT_TAG main # or an actual git SHA if you don't like to live dangerously
)
FetchContent_MakeAvailable(cppfront)
add_executable(main main.cpp2 test.cpp2)
test.cpp2
gogo: () -> int = {
return 2123;
}
main.cpp2
#include "test.cpp"
main: () = {
s: std::string = "Fred";
std::cout <<gogo()<< "Hello, world!\n";
}
openning vscode
build yield
[build] ld: 1 duplicate symbols
[build] clang: error: linker command failed with exit code 1
.h
from cppecho '#pragma once' > test.h
sed -n '/=== Cpp2 type declarations/,/=== Cpp2 type definitions and function declarations/p' build/_cppfront/test.cpp >> test.h
change main.cpp2 to
#include "test.h"
main: () = {
s: std::string = "Fred";
std::cout <<gogo()<< "Hello, world!\n";
}
I think the problem is here
https://github.com/hsutter/cppfront/issues/594
No way to produce separated .h
files without -pure-cpp2
, however export in modules is not supported yet.
ok, thanks to https://github.com/isidorostsa/RayTrayCpp2
I think settings the CMakeLists.txt to
cmake_minimum_required(VERSION 3.23)
project(example)
include(FetchContent)
FetchContent_Declare(
cppfront
GIT_REPOSITORY https://github.com/modern-cmake/cppfront.git
GIT_TAG main # or an actual git SHA if you don't like to live dangerously
)
FetchContent_MakeAvailable(cppfront)
add_executable(main main.cpp2)
set(cpp2headers
test.h2
)
#set(CPPFRONT_FLAGS "-pure-cpp2")
cppfront_generate_cpp(cpp1headers ${cpp2headers})
target_sources(main PUBLIC ${cpp1headers})
actually works, it does not produce include files but it compiles, unlike putting h2
files directly to target_sources
...
I've created
test.cpp2
I do not use modules, how do I include that?
I've created manually
test.h
with#pragma once
in the same source folder with thebut I'm not sure it is the right way of doing it, because I have to update that file manually whenever
gogo
signature changes.I've been thinking maybe
sed
can help, becausecppfront
has no switch todo so