Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when using modules - CMake can not determine linker language for target: foo #140

Closed
shemeshg opened this issue Apr 30, 2024 · 3 comments · May be fixed by #145
Closed

when using modules - CMake can not determine linker language for target: foo #140

shemeshg opened this issue Apr 30, 2024 · 3 comments · May be fixed by #145
Labels
bug Something isn't working

Comments

@shemeshg
Copy link

shemeshg commented Apr 30, 2024

  • error Files are not created for cppfront in the build folder

CMakeLists.txt

cmake_minimum_required(VERSION 3.28)
project(std_module_example CXX)

# Turning off extensions avoids an issue with the clang 16 compiler
# clang 17 and greater can avoid this setting
set(CMAKE_CXX_EXTENSIONS OFF)
# Set the version of C++ for the project
set(CMAKE_CXX_STANDARD 20)

add_subdirectory(cppfront)
# Create a library
add_library(foo)
# Add the module file to the library
target_sources(foo
  PUBLIC
    FILE_SET CXX_MODULES FILES
      foo.cpp2
)
# Create an executable
add_executable(hello main.cxx)
# Link to the library foo
target_link_libraries(hello foo cppfront)

main.cxx

import shalom;

int main()
{
  foo f;  
  f.helloworld();
  return 0;
}

foo.cpp2 (change to foo.cxx and it will work)

// Global module fragment where #includes can happen
module;
#include <iostream>

// first thing after the Global module fragment must be a module command
export module shalom;

export class foo {
public:
  foo();
  ~foo();
  void helloworld();
};

foo::foo() = default;
foo::~foo() = default;
void foo::helloworld() { std::cout << "hello world\n"; }
@alexreinking
Copy link
Contributor

Aha looks like we have to scan the file sets too

@shemeshg
Copy link
Author

shemeshg commented Jun 1, 2024

also maybe authoring modules aren't supported yet:

hsutter/cppfront#1059

@alexreinking
Copy link
Contributor

After merging #145, this build will work:

cmake_minimum_required(VERSION 3.29)
project(std_module_example CXX)

set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 20)

find_package(cppfront REQUIRED)

add_library(foo)
target_sources(
    foo
    PUBLIC
    FILE_SET CXX_MODULES
    FILES foo.cpp2
)

add_executable(main main.cxx)
target_link_libraries(main PRIVATE foo)

@alexreinking alexreinking added the bug Something isn't working label Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants