Difference between <stdafx.h> and "stdafx.h" - visual-c++

I have unit a.cpp that is used in several projects in subdirectory libA. Some of project are using precompiled headers, while others -not. In this case projects that use precompiled header must have line:
#include <stdafx.h>
and projects that are not using PCH must have line:
#include "..\stdafx.h"
Wise verse is not working.
Why project sees stdafx.h file in different way when project uses PCH or not?
UPD.
When I replace line #include <stdafx.h> with #include "..\stdafx.h" in project that uses precompiled header i have error
Error 19 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Directory structure is the same in both projects.

There is no (or there should not be any) difference between <stdafx.h> and "stdafx.h". The only significant difference is that one project "sees" the file in current folder, and the other project sees it in parent folder. This difference is controlled by compiler option Additional Include Directories. One project has libA in it, and the other does not have it.

Related

CMake Precompiled Headers not including correctly for Visual Studio

So I've recently started using the "new" target_precompile_headers command for CMake to generate and include my precompiled headers.
But for some reason it doesn't seem to work at all the way I want it.
I do understand that the usage of this command is to provide the list of headers to include in your pch and that CMake itself generates the actual pch. This seem to work just fine as I can see the pchs generated for each config & project in my solution.
However looking at the project properties, and more specifically looking at the .cpp properties the /FI command is always empty, which means no files are force included.
This also means that none of my cpp catches that I am using pch at all and my compile fails.
Does anyone have any suggestions on what could be wrong?
// Example of a CMakeLists.txt which defines a static lib using PCH
file(GLOB ALL_SOURCE_FILES "*.cpp" "*.h")
add_library(MyLib STATIC ${ALL_SOURCE_FILES})
target_precompile_headers(MyLib PRIVATE MyHeader.h)
Below you see my own lib created with the snippet above. As you can see, no Forced Include file is added, thus no cpp files gets the PCH included.
I found this workaround: Adding the compiler option manually...
if(MSVC)
target_compile_options(YourProject PRIVATE "/FI${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${PROJECT_NAME}.dir/$<CONFIG>/cmake_pch.hxx")
endif()
(Currently using Cmake 3.24.1 with cmake_minimum_required(VERSION 3.18) in the file)

VC++ included headers cannot be found

I downloaded sample code that uses a 'header only' library and even though I have included the library path in my VC++ project, I keep getting the error:
fatal error C1083: Cannot open include file: 'websocketpp/config/asio_no_tls.hpp': No such file or directory
Library header files location:
D:\websocketpp
D:\websocketpp\config
Here are the first few lines of the example program echo_server.cpp:
#include "stdafx.h"
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
The included files do exist in the directories above. I have specified the directories as follows:
Visual C++ Directories / Include Directories /
D:\websocketpp
C/C++ / General / Additional Include Directories
D:\websocketpp\config
Does someone know what the problem is?
It was a stupid mistake. I moved the entire directory structure into a new folder:
D:\websocket\websocket
D:\websocket\websocket\config

Newbie to C++; visual studio 2012 include path

I installed VS2012 today and started learning C++.
I wrote a Hello World program with #include <iostream.h>.
On build I get the error; C1083: Can not open include file... I believe this is an include path problem.
I tried editing the Include Directories in the VC++ Property Page but nothing I try works. Currently the include directories path has :
$(VCInstallDir)include
$(VCInstallDir)atlmfc\include
$(WindowsSDK_IncludePath)
Any thoughts on how to fix?
It's not <iostream.h>, it's just <iostream>.
For standard c++ headers you must not put the .h so :
#include <iostream.h>
should become :
#include <iostream>
After that, if you are beginning with cplusplus, here is a link with the standard library headers (and articles about c++). It is a great help to have this website : http://www.cplusplus.com/reference/

"already defined" error while adding cpp to solution explorer

I have dll project that includes additionally A.h header file. A.cpp includes A.h and B.cpp that has o header. If I do add B.cpp to visual c++ project compiler reports many errors :
Error 9 error LNK2005: "wchar_t * __stdcall aaa(int)" (?aaa##YGPA_WH#Z) already defined in A.obj C:\P\B.obj pr1
There are no problems and project compiles fine in case if I leave B.cpp in project directory, but not add it to project.
That is the problem with adding B.cpp file?
I thought that extensions has no influence and might be whatever you want. Correct me if I'm wrong, but I think I can rename B.h to B.fss , define this in source and compiler should compile
Your b.cpp will be automatically compiled if you include it in the project; and as you are including contents of the same file elsewhere as well, the code in it will be compiled again, resulting in duplicate definition errors
Basically if you include something that has definitions instead of declarations in one .cpp file and also add it to the project of course you will get multiple definition errors - move the definitions for the stuff in B.cpp to B.h and include that in A.cpp. The issue is not file extensions, the issue is that you need to understand that multiple definitions of the same thing will lead to such errors.
#include is for header files, not other .cpp files.
Remove #include "B.cpp" from A.cpp, and things will start behaving properly.
Or rename B.cpp to B.h if you intend to include it.

VS 10 includes, and I have a linker error

I am using Visual Studio 10 to program in C++
The 1st part of my program is
//Includes
//#include <LEDA\numbers> //fatal error C1083: Cannot open include file: 'LEDA\numbers': No such file or directory
#include <LEDA/numbers/real.h>
//Why do I get a linker error here
//All.obj : error LNK2001: unresolved external symbol "class leda::memory_manager leda::std_memory_mgr" (?std_memory_mgr#leda##3Vmemory_manager#1#A)
#include <LEDA\numbers\integer.h> //Here I used the system to write most of it for me
#include <LEDA/numbers/integer.h> //Include LEDA. So 2 things
//1. including the same file twice does not matter
//2. forward slashes and backward slashes are the same
//I tried to use a wild card and said #include <LEDA/numbers/*>
//But that did not work
#include <LEDA/numbers/rational.h>
#include <LEDA/core/string.h>
#include <LEDA/core/array.h>
#include <LEDA/numbers/bigfloat.h>
//The sqrt does not work
#include <iostream> //include ordinary C++
#include <math.h>
and I have a LINKER error
I have tried specifying which libraries to use by specifying the LIB User Environment symbol
I have tried specifying which libraries to use by specifying the
Include Directories and
Library Directories
in the properties of my Project
I have made a mistake somewhere, BUT where is it
There are several mistakes in this program:
LEDA\numbers is apparently a directory, not an include file. So you shouldn't try to include it.
(conceptual) #include statements don't help in resolving linker errors at all. Instead, you need to specify the libraries you want to link with to the linker; libraries are files that end in .lib. Go to the project settings, and add the libraries containing the missing symbols.
#include <abcd.h> // looks for the include abcd.h in the INCLUDES path.
#include "abcd.h" // looks for the include abcd.h in the current path and then INCLUDES path.
From your description it looks like your LEDA lib in under your current directory. Try using "" instead of <> and see if it fixes your errors.

Resources