3

I have a solution called Almond which contains two projects:

  • Almond
  • Sandbox

Almond is a shared library created using C++20 modules. Sandbox is supposed to be an executable that links to Almond at runtime (also configured for C++20). I added almond as a reference in Sandbox. It looks like I should be able to import modules from the library and I even get intellisense on it. Do I also have to do things like __declspec(dllexport) and __declspec(dllimport)? If so, how? I couldn't find any docs that explained this.

Almond: src/Lib.ixx

export module Lib;

export int Three() {
    return 3;
}

Sandbox: src/Main.cpp:

import Lib;

import <iostream>;

int main() {
    std::cout << Three() << std::endl;
}

Almond builds fine but building sandbox gives me the following errors:

Severity    Code    Description Project File    Line    Suppression State
Error   C2065   'endl': undeclared identifier   Sandbox C:\source\Almond\Sandbox\src\Main.cpp   6   
Error   C2230   could not find module 'Lib' Sandbox C:\source\Almond\Sandbox\src\Main.cpp   1   
Error   C7612   could not find header unit for 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\iostream' Sandbox C:\source\Almond\Sandbox\src\Main.cpp   3   
Error   C2039   'cout': is not a member of 'std'    Sandbox C:\source\Almond\Sandbox\src\Main.cpp   6   
Error   C2065   'cout': undeclared identifier   Sandbox C:\source\Almond\Sandbox\src\Main.cpp   6   
Error   C3861   'Three': identifier not found   Sandbox C:\source\Almond\Sandbox\src\Main.cpp   6   
Error   C2039   'endl': is not a member of 'std'    Sandbox C:\source\Almond\Sandbox\src\Main.cpp   6   
NaniNoni
  • 155
  • 11

1 Answers1

-6

Im not sure what you are trying to do fully, but try using namespaces, instead of modules, its a lot more simple in my opinion.

Namespaces are essentially modules like std, they contain members (classes, vars, or functions) that can be accessed by x::y:

Almond.h:

namespace Almond{

    int Three(){return 3;}
}

Sandbox.h:

#include "Almond.h"
#include <iostream>

using namespace Almond; // optional

int main(){
    std::cout << Three() << std::endl;
}

We use the namespace Almond declared in the Almond.h file, and then we can use all of its members!

TBCM
  • 58
  • 6