git 如何解决Visual Studio 2022社区中的多存储库解决方案问题

nbysray5  于 11个月前  发布在  Git
关注(0)|答案(1)|浏览(149)

我的测试解决方案的结构如下:

TestApp (solution)  
    ├─ TestApp (project)    
    ├─ Submodules  
           ├─ TestLib (solution)   
                 ├─ TestLib (project)  
                       ├─ 3rd_party  
                       |      ├─ include  
                       |            ├─ nlohmann  
                       ├─ pch.h  
                       ├─ TString.h  
                       ├─ TargetEntity.h

字符集
nlohmann是JSON库。TestLib是一个静态库,它包含在TestApp中作为引用。TestLibTestApp repo中的git子模块。TestAppAdditional include directories中也有以下路径:

$(SolutionDir)Submodules\TestLib\TestLib\3rd_party\include;
    $(SolutionDir)Submodules\TestLib\;
    %(AdditionalIncludeDirectories)


下面是完整的代码:

TestApp

main.cpp

#include "TestLib/TargetEntity.h"
#include "TestLib/TString.h"
//#include "nlohmann/json.hpp"

int main()
{
    //nlohmann::json json;
    //json["abc"] = 765;
    TargetEntity te;
    TString      ts;
}

TestLib

pch.h

#ifndef PCH_H
    #define PCH_H
    
    #define WIN32_LEAN_AND_MEAN
    #include "TString.h"
    //#include "nlohmann/json.hpp"
    
    #endif // PCH_H


pch.cpp

#include "pch.h"


TString.h

#pragma once
    
    #include <string>
    
    using TString = std::wstring;


TargetEntity.h

#pragma once
    
    //#include "TString.h" // Uncomment to get rid of error
    //#include "nlohmann/json.hpp" // Uncomment to get rid of error
    
    class TargetEntity
    {
    public:
        virtual ~TargetEntity() = default;
    
        //void InitializeFromJson(const nlohmann::json& json) {}
    
    protected:
        TString url;
    };


TargetEntity.cpp

#include "pch.h"
#include "TargetEntity.h"


TestLib作为单独的解决方案编译时很好,当作为TestApp内部的项目编译时(我的意思是,当你只编译lib时)。但是当我试图编译TestApp VS时,在TargetEntity内部显示错误:

Build started...
1>------ Build started: Project: TestLib, Configuration: Debug x64 ------
1>pch.cpp
1>TargetEntity.cpp
1>TestLib.vcxproj -> ...\Temp\TestApp\Build-TestLib-x64-Debug\TestLib.lib
2>------ Build started: Project: TestApp, Configuration: Debug x64 ------
2>TestApp.cpp
2>...\Temp\TestApp\Submodules\TestLib\TestLib\TargetEntity.h(13,13): error C3646: 'url': unknown override specifier
2>...\Temp\TestApp\Submodules\TestLib\TestLib\TargetEntity.h(13,16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>Done building project "TestApp.vcxproj" -- FAILED.


所以,在TestApp的编译过程中,VS似乎忽略了TestLib的预编译头。我知道,multi-repo是一个预览功能,但我的情况对我来说似乎是“显而易见的”,可能有人知道如何解决这个问题。
我注意到在TargetEntity中包含相应的头文件解决了这个问题,但我不想在整个库中这样做。

**更新:**我添加了完整的代码和完整的构建输出。为了简单起见,我还注解了nlohmann相关的代码-问题仍然存在。

7ajki6be

7ajki6be1#

pch.h在你的main.cpp和#include pch.h头文件之前丢失。

#include "pch.h"
#include "TestLib/TargetEntity.h"
#include "TestLib/TString.h"
//#include "nlohmann/json.hpp"

int main()
{
    //nlohmann::json json;
    //json["abc"] = 765;
    TargetEntity te;
    TString      ts;
}

字符集

相关问题