B
bikeaccdnt
I have been trying to simply include a header file for a project. No matter what I do it will now work unless I copy the source and header files to the project that uses it. Obviously this is not acceptable as the classes I have written will be used in many projects and I only want one version.
Folders:
C:\Temp\EmptyLinuxProject - This is an empty Linux project that creates a libEmptyLinuxProject.a that contains one class called SimpleClass.
Two files are in SimpleClass. SimpleClass.h, SimpleClass.cpp
SimpleClass.h
#pragma once
class SimpleClass
{
private:
int iInteger;
public:
SimpleClass();
~SimpleClass();
int GetInteger();
};
SimpleClass.cpp
#include "SimpleClass.h"
SimpleClass::SimpleClass()
{
iInteger = 100;
}
SimpleClass::~SimpleClass()
{
iInteger = 0;
}
int SimpleClass::GetInteger()
{
return iInteger;
}
I created EmptyLinuxProject and added SimpleClass.cpp and h and changed the output type to .a
That works fine, it compiles and creates a libEmptyLinuxProject.a
Here is the problem:
I create a new project LinuxConsoleApp
In Properties:All Configurations, All Platforms
VC++ Directories
Include Directories
C:\Temp\EmptyLinuxProject;$(IncludePath)
C/C++
Additional Include Directories:
C:\Temp\EmptyLinuxProject;%(AdditionalIncludeDirectories)
Linker
Additional Library Directories
C:\Temp\EmptyLinuxProject;%(AdditionalLibraryDirectories)
main.cpp
#include <cstdio>
#include <SimpleClass.h>
int main()
{
printf("hello from LinuxConsoleApp!\n");
return 0;
}
really doesn't do anything but when compiled I get No such file or directory.
Severity Code Description Project File Line Suppression State
Error SimpleClass.h: No such file or directory LinuxConsoleApp C:\Temp\LinuxConsoleApp\main.cpp 2
Notes:
In LinuxConsoleApp main.cpp I have tried the following to resolve:
#include "SimpleClass.h"
#include <SimpleClass.h>
#include <C:\Temp\EmptyLinuxProject\SimpleClass.h>
#include <C:\\Temp\\EmptyLinuxProject\\SimpleClass.h>
#include <..\EmptyLinuxProject\SimpleClass.h>
The only way I can use this class is to add a new item to the LinuxConsoleApp SimpleClass.cpp and SimpleClass.h, Copy the code from EmptyLinuxProject and it will compile and work but now I have two copies of the same code.
If I try to add the SimpleClass.cpp and SimpleClass.h as an existing item it will not work.
There is definitely something wrong with how VS handles new items vs. existing
When I use the Add Existing Item these lines are inserted into the .vcxproj file
<ItemGroup>
<ClCompile Include="..\EmptyLinuxProject\SimpleClass.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\EmptyLinuxProject\SimpleClass.h" />
</ItemGroup>
When I use the Add new item it adds these lines
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="SimpleClass.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="SimpleClass.h" />
</ItemGroup>
so it looks like the compiler cant resolve the directories for existing items.
Note: I manually changed the relative path to the full path and it does the same thing
Continue reading...
Folders:
C:\Temp\EmptyLinuxProject - This is an empty Linux project that creates a libEmptyLinuxProject.a that contains one class called SimpleClass.
Two files are in SimpleClass. SimpleClass.h, SimpleClass.cpp
SimpleClass.h
#pragma once
class SimpleClass
{
private:
int iInteger;
public:
SimpleClass();
~SimpleClass();
int GetInteger();
};
SimpleClass.cpp
#include "SimpleClass.h"
SimpleClass::SimpleClass()
{
iInteger = 100;
}
SimpleClass::~SimpleClass()
{
iInteger = 0;
}
int SimpleClass::GetInteger()
{
return iInteger;
}
I created EmptyLinuxProject and added SimpleClass.cpp and h and changed the output type to .a
That works fine, it compiles and creates a libEmptyLinuxProject.a
Here is the problem:
I create a new project LinuxConsoleApp
In Properties:All Configurations, All Platforms
VC++ Directories
Include Directories
C:\Temp\EmptyLinuxProject;$(IncludePath)
C/C++
Additional Include Directories:
C:\Temp\EmptyLinuxProject;%(AdditionalIncludeDirectories)
Linker
Additional Library Directories
C:\Temp\EmptyLinuxProject;%(AdditionalLibraryDirectories)
main.cpp
#include <cstdio>
#include <SimpleClass.h>
int main()
{
printf("hello from LinuxConsoleApp!\n");
return 0;
}
really doesn't do anything but when compiled I get No such file or directory.
Severity Code Description Project File Line Suppression State
Error SimpleClass.h: No such file or directory LinuxConsoleApp C:\Temp\LinuxConsoleApp\main.cpp 2
Notes:
In LinuxConsoleApp main.cpp I have tried the following to resolve:
#include "SimpleClass.h"
#include <SimpleClass.h>
#include <C:\Temp\EmptyLinuxProject\SimpleClass.h>
#include <C:\\Temp\\EmptyLinuxProject\\SimpleClass.h>
#include <..\EmptyLinuxProject\SimpleClass.h>
The only way I can use this class is to add a new item to the LinuxConsoleApp SimpleClass.cpp and SimpleClass.h, Copy the code from EmptyLinuxProject and it will compile and work but now I have two copies of the same code.
If I try to add the SimpleClass.cpp and SimpleClass.h as an existing item it will not work.
There is definitely something wrong with how VS handles new items vs. existing
When I use the Add Existing Item these lines are inserted into the .vcxproj file
<ItemGroup>
<ClCompile Include="..\EmptyLinuxProject\SimpleClass.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\EmptyLinuxProject\SimpleClass.h" />
</ItemGroup>
When I use the Add new item it adds these lines
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="SimpleClass.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="SimpleClass.h" />
</ItemGroup>
so it looks like the compiler cant resolve the directories for existing items.
Note: I manually changed the relative path to the full path and it does the same thing
Continue reading...