Building with/ Using VS2010
Platform SDK (Microsoft Windows SDK v7.1) installed.
When i try to build the Sample LSP (located in C:\Program Files\Microsoft Platform SDK\Samples\NetDS\WinSock\LSP)
!--BEGIN RESOLVED--!
I get 16 of the same two errors below.
Error 1 error C1083: Cannot open include file: 'nt.h': No such file or directory c:\program files\microsoft sdks\windows\v7.1\samples\netds\winsock\lsp\nonifslsp\lspdef.h 22 1 LSP
Error 7 error C1083: Cannot open include file: 'lspcommon.h': No such file or directory c:\program files\microsoft sdks\windows\v7.1\samples\netds\winsock\lsp\install\instlsp.h 35 1 LSP
When i added the source code of this sample to VS, i use File>New ProjectFrom Existing Code.
Once i do that, VS starts importing all the Platform SDK include files. I was reading elsewhere that not having the includes from PSDK would cause problems, but this doesnt seem to be the case here.
!--END RESOLVED--!
I now run into 3 more errors after fixing the above problem:
Error 1 error LNK2005: "struct _GUID gProviderGuid" (?gProviderGuid##3U_GUID##A) already defined in lspguid.obj C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\instlsp.obj LSP
Error 6 error CVT1100: duplicate resource. type:MANIFEST, name:1, language:0x0409 C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\CVTRES LSP
Error 7 error LNK1123: failure during conversion to COFF: file invalid or corrupt C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\LINK LSP
I have not changed any of the contents/files in the LSP sample.
Currently I'm just trying to build it.
Any insight on this would be helpful.
Thanks.
The file lspcommon.h is part of the LSP sample, you should be able to find it in the 'common' subfolder. (C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\common)
If you double click on one of your errors the editor will open focused on the line that's giving problems. Do that for lspdef.h line 22 and you'll see the code looks like this...
#ifndef _PSDK_BLD
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#endif
That means, the nt.h file (and two others) is only included if the macro _PSDK_BLD is not defined. Look a little lower at line 35 and you'll see the code looks like this...
#ifndef _PSDK_BLD
#include <lspcommon.h>
#else
#include "..\common\lspcommon.h"
#endif
In this case, if the macro is not defined the code includes the file lspcommon.h, but if the macro is defined then the code includes the file lspcommon.h from the common foider.
It seems likely then that your problems are happening because _PSDK_BLD is not defined. From the style of the #ifdef it doesn't look like the macro has to be defined to any specific value, just defined.
In Visual Studio, go to Project Properties, drill down to C/C++ and then Preprocessor. Then find the preprocessor definitions line and click on the value. Now select edit and add _PSDK_BLD to the list of preprocessor definitions.
Watch out for that leading underscore, and remember to make the change for Debug and Release configurations (and for all the platforms you may have defined)
The error LNK2005 means that the linker found two definitions for the object it is trying to link - which is a problem because there's no way for the linker to be able to tell which of the two definitions it should use.
In this particular case, the object the linker is trying to resolve is "struct _GUID gProviderGuid". If you look in the files instlsp.h, lspdef.h (both of them) and lspcommon.h you'll see code that looks like this
extern GUID gProviderGuid;
That declares an external variable called gProviderGuid of type GUID (which is a struct). The linker has to resolve that external reference in any file that included one of those header files and then made a reference to gProviderGuid.
From the "already defined in lspguid.obj" part of the error we know the linker has looked inside the file lspguid.obj and found a definition of gProviderGuid. Sure enough, if we look inside lspguid.cpp we can see a definition of gProviderGuid with a value starting 0xc5fabbd0.
From the "C:\Program Files\Microsoft SDKs\Windows\v7.1\Samples\netds\winsock\lsp\instlsp.obj" part of the same error we know that the linker has also looked inside the file instlsp.obj and found a second definition of gProviderGuid. If we look inside intlsp.cpp we can see another definition of gProviderGuid (this time without any value).
The problem then is that the linker is looking in both lspguid.obj and intlsp.obj and finding conflicting definitions of gProviderGuid.
Those two files should not be part of the same build so we shouldn't expect a single run of the linker to read them both at the same time.
The LSP project is made up of four parts: lspcommon which is used to generate the static library lspcommon.lib; ifslsp which is used to generate the file ifslsp.dll; nonifslsp which is used to generate the file nonifslsp.dll and install which is used to generate the file Instlsp.exe. See the readme.txt file in lsp and the makefile files in the various folders for more details.
If you are going to build LSP inside Visual Studio, you really need four different projects in your solution, one each for lspcommon, ifslsp, nonifslsp and install.
Add this define to your build: _PSDK_BLD
It would solve your problem
Try changing #include <nt.h> to #include <winnt.h> and see if it builds.
Related
I've just been beaten (rather hardly) on the head by some non-trivial warning from Visual Studio 2010 (C++).
The compilation gave the following output:
1 Debug\is.obj : warning LNK4042: object specified more than once; extras ignored
1 Debug\make.obj : warning LNK4042: object specified more than once; extras ignored
1 Debug\view.obj : warning LNK4042: object specified more than once; extras ignored
1 identity.obj : error LNK2019: unresolved external symbol void __cdecl
test::identity::view(void) (?view#identity#test##YAXXZ) referenced in function void __cdecl test::identity::identity(void) (?identity#0test##YAXXZ)
1 identity.obj : error LNK2019: unresolved external symbol void __cdecl test::identity::make(void) (?make#identity#test##YAXXZ) referenced in function void __cdecl test::identity::identity(void) (?identity#0test##YAXXZ)
1 range.obj : error LNK2019: unresolved external symbol void __cdecl test::range::is(void) (?is#range#test##YAXXZ) referenced in function void __cdecl test::range::range(void) (?range#0test##YAXXZ)
Linker errors are always a pain to debug... but there were unresolved references, and so I checked... but the source is well-formed... and finally it hit me:
My folder hierarchy looks like so:
src/
identity/
is.cpp
make.cpp
view.cpp
range/
is.cpp
make.cpp
view.cpp
and so does the hierarchy in the Solution (I always set it up so that it mimicks the "real" folder structure).
And the diagnostic outputs:
Debug\is.obj
Debug\make.obj
Debug\view.obj
Along with a warning which says that the .obj has been passed twice to the linker and that one will be ignored.
Search no more: Visual has neatly flatten my folder hierarchy, and therefore is unable to neatly compile the source.
At the moment, I am simply thinking of renaming the files, that should cover the issue...
... but is there a way to have Visual Studio NOT flatten the file hierarchy ?
I had a similar problem with linker warning LNK4042: object specified more than once; extras ignored. In my case Visual Studio was trying to compile both header and source files with the same name - MyClass.h and MyClass.cpp. It happened because I renamed .cpp file to .h and Visual Studio got confused. I noticed the problem by looking at the compiler logs in the Debug directory. To resolve just remove .h file from the project then add it again.
Just wanted to cross post what I believe to be the answer, if you open the properties for the entire project, and the change the value under C/C++ -> Output Files -> "Object File Name" to be the following:
$(IntDir)/%(RelativeDir)/
Under VS 2010, I believe this will disambiguate all of the object files (as I believe windows won't let you under any crazy circumstances have two files with the same names in the same directory). Please also check out the details here.
Right-click the .cpp file in the Solution Explorer window, Properties, C/C++, Output Files, Object File Name setting. The default is $(IntDir)\, that's what is doing the flattening. All the .obj file will go into $(IntDir), the "Debug" directory in the debug configuration.
You can change the setting, say $(IntDir)\is2.obj. Or select all the files from one group (use Shift+Click) and change the setting to, say, $(IntDir)\identity\
Or you can change the .cpp filename so that .obj files don't overwrite each other. Having files with the exact same name in two directories is a bit odd.
Or you can create multiple projects, creating, say, .lib projects for the files in identity and range. Commonly done in makefile projects for example. That does however make managing the compile and link settings more of a hassle unless you use project property sheets.
Right click on header file -> Property -> ItemType (select C/C++ Header). Do the same with Cpp file but select C/C++ Compiler (it's work for me)
Alternatively to deleting and making a new file you can change the compile/include settings.
Go to your project.vcxproj file, open it with an editor, find the html like line <ItemGroup>.
It should look something like:
<ItemGroup>
<ClCompile Include="implementation.cpp" />
</ItemGroup>
and
<ItemGroup>
<ClInclude Include="declaration.hpp" />
</ItemGroup>`
Assuming your implementation files are .cpp and your declarations are .hpp. Make sure your all your implementation files are listed between the first section if you have more then one and likewise for the second section for multiple declaration files.
I had this problem with stdafx.cpp. Somehow stdafx.cpp got duplicated, so there was a second StdAfx.cpp (mind the different case).
After I removed the StdAfx.cpp everything worked fine!
Using VS 2010.
I use $(IntDir)\%(Directory)\ under C/C++ -> Output Files -> "Object File Name".
I used to have in the same project .c and .cpp files with the same filenames. The files were in folders all over the place and the solutions provided by others created a mess, and folder hell (in my case). Even Release builds would overwrite Debug builds!
A good (not perfect) solution would be to use $(ParentName), but for some reason beyond anyone's grasp it has been removed from later versions of Visual Studio (2015+).
What I use succesfully now is:
$(IntDir)%(Filename)%(Extension).obj
which at least separates .c built object files from .cpp.
I'd like to point out one possible reason for why the ItemType of a .h file would change from C/C++ header to C/C++ compiler:
In the Solution Explorer window of VS (2019 here), right click the project name, choose Add -> New Item;
Select the C++ File (.cpp) template, but type something.h in the name input area, then click OK to add it;
Then you'll encounter the LNK4042 warning if the something.h file be included within more than one .cpp files.
I just overcame a similar error message, and lots more with the procedure below. Symptom: one linker error for every invocation of every function defined in a particular header, plus one at the end of output for every function defined in the header.
Then I remembered that when I had originally created this header, I accidentally had selected "add->new item->c++ file" and though I named it 'whatever.h', it seems Visual Studio considered them both the same kinds of files because of the incorrect action I used to add one. Examining the build output logs made this obvious.
SOLUTION (Using VS Community 2019)
Back up project first (just to be safe).
Right-click the offending header file and select "Exclude from project" (this will not delete them; the VS project will just ignore them).
Do same for the matching .c or .cpp file.
Do Build->Clean on project
Do Build->Rebuild on project
-- there of course will be errors---
Right-click Header Files->Add->Existing Item, then select the .h file
Right-click Source Files->Add->Existing Item, the select the .c or .cpp file
Do Build->Rebuild on project.
This completely cleaned it up for me, relieving me of many irritating linker errors including LNK4042 from the title of this question.
I resolved it changing filenames in my project. There was two files named main.c and main.cpp. I changed one of them and worked.
I am working in visual studio and i have got two projects in a solution.
I want to refer to header file of second project in my main-project.
I added second-prj as a reference to my main-prj,. But when i write like
#include "Second_Project_File.h"
in my main-prj it gives compile errors :
fatal error C1083: Cannot open include file: 'Second_Project_File.h': No such file or directory.
Then i looked at the folders and gave relative path like
#include "..\Second_Project_Folder\Second_Project_File.h"
it compiled but gave error :
main-prj.exe not found or not built by the last incremental link; performing full link
Embedding manifest...
What should i do?
i donot want to work with this kind of including header files
#include "..\somefolder\header.file.h"
How to do this in visual studio.
Thanks.
I'm a real beginner and I'm programming in C++ using Visual Studio.
I've a simple cpp code that recalls some functions written in a .c and .h file. I included that file by means of #include directive and the IDE "sees" the function.
When I compile, I get this
Error 7 error LNK2019: unresolved external symbol _IMUsendAccelToFIFO referenced in function _main D:\Cprojects\Pencil\Pencil\Pencil.obj Pencil
What am I missing here?
Thank you all!
It is a linker error, not a compiler error. The compiler is happy, it saw the declaration of function in the .h file. The linker isn't, it cannot find the definition of the function.
Add the .c file to your project.
If you get an error in Visual Studio you can actually google for the error code and you will get pretty extensive information for that. In this case, googling LNK2019 gives this MSDN page as first hit, which also provides some examples on how you get the error.
Your vendor should have provided some .lib files for you (usually found in a folder named lib?). Make sure that these are added in the project via:
Project > Properties > Configuration Properties > Linker > Input > Additional Dependencies
You could also see if there is any "get started" information for you from your vendor, which explains which dependencies you have to include in your project.
If you feel unsure of what a compiler and what a linker does, pick up a book that explains it, or browse some free alternatives.
Are you using ghettopilot? that's the only reference I can find on the web to the function you're missing. If you are, then you need to include the .lib file for that library in your link options.
Visual Studio will compile .c files as C and .cpp files as C++ by default, and this can cause trouble because if you want to call functions defined in a .c file from a .cpp file, then you must wrap the header in extern "C" { }, as the compiler will expect all functions not declared extern "C" to be from C++. This is because of an implementation detail called name mangling. Alternatively, you could force all files to be compiled as C or as C++ in the project settings.
Solved! Thank you very much!
The libraries I was using needed to be built. I tried but I couldn't build them as I used to get "heap space" error!
I installed Visual Studio 2005 (with which the code was produced by the vendor) and it worked at first attempt! There are probably some back-compatibility issues..
I've just been beaten (rather hardly) on the head by some non-trivial warning from Visual Studio 2010 (C++).
The compilation gave the following output:
1 Debug\is.obj : warning LNK4042: object specified more than once; extras ignored
1 Debug\make.obj : warning LNK4042: object specified more than once; extras ignored
1 Debug\view.obj : warning LNK4042: object specified more than once; extras ignored
1 identity.obj : error LNK2019: unresolved external symbol void __cdecl
test::identity::view(void) (?view#identity#test##YAXXZ) referenced in function void __cdecl test::identity::identity(void) (?identity#0test##YAXXZ)
1 identity.obj : error LNK2019: unresolved external symbol void __cdecl test::identity::make(void) (?make#identity#test##YAXXZ) referenced in function void __cdecl test::identity::identity(void) (?identity#0test##YAXXZ)
1 range.obj : error LNK2019: unresolved external symbol void __cdecl test::range::is(void) (?is#range#test##YAXXZ) referenced in function void __cdecl test::range::range(void) (?range#0test##YAXXZ)
Linker errors are always a pain to debug... but there were unresolved references, and so I checked... but the source is well-formed... and finally it hit me:
My folder hierarchy looks like so:
src/
identity/
is.cpp
make.cpp
view.cpp
range/
is.cpp
make.cpp
view.cpp
and so does the hierarchy in the Solution (I always set it up so that it mimicks the "real" folder structure).
And the diagnostic outputs:
Debug\is.obj
Debug\make.obj
Debug\view.obj
Along with a warning which says that the .obj has been passed twice to the linker and that one will be ignored.
Search no more: Visual has neatly flatten my folder hierarchy, and therefore is unable to neatly compile the source.
At the moment, I am simply thinking of renaming the files, that should cover the issue...
... but is there a way to have Visual Studio NOT flatten the file hierarchy ?
I had a similar problem with linker warning LNK4042: object specified more than once; extras ignored. In my case Visual Studio was trying to compile both header and source files with the same name - MyClass.h and MyClass.cpp. It happened because I renamed .cpp file to .h and Visual Studio got confused. I noticed the problem by looking at the compiler logs in the Debug directory. To resolve just remove .h file from the project then add it again.
Just wanted to cross post what I believe to be the answer, if you open the properties for the entire project, and the change the value under C/C++ -> Output Files -> "Object File Name" to be the following:
$(IntDir)/%(RelativeDir)/
Under VS 2010, I believe this will disambiguate all of the object files (as I believe windows won't let you under any crazy circumstances have two files with the same names in the same directory). Please also check out the details here.
Right-click the .cpp file in the Solution Explorer window, Properties, C/C++, Output Files, Object File Name setting. The default is $(IntDir)\, that's what is doing the flattening. All the .obj file will go into $(IntDir), the "Debug" directory in the debug configuration.
You can change the setting, say $(IntDir)\is2.obj. Or select all the files from one group (use Shift+Click) and change the setting to, say, $(IntDir)\identity\
Or you can change the .cpp filename so that .obj files don't overwrite each other. Having files with the exact same name in two directories is a bit odd.
Or you can create multiple projects, creating, say, .lib projects for the files in identity and range. Commonly done in makefile projects for example. That does however make managing the compile and link settings more of a hassle unless you use project property sheets.
Right click on header file -> Property -> ItemType (select C/C++ Header). Do the same with Cpp file but select C/C++ Compiler (it's work for me)
Alternatively to deleting and making a new file you can change the compile/include settings.
Go to your project.vcxproj file, open it with an editor, find the html like line <ItemGroup>.
It should look something like:
<ItemGroup>
<ClCompile Include="implementation.cpp" />
</ItemGroup>
and
<ItemGroup>
<ClInclude Include="declaration.hpp" />
</ItemGroup>`
Assuming your implementation files are .cpp and your declarations are .hpp. Make sure your all your implementation files are listed between the first section if you have more then one and likewise for the second section for multiple declaration files.
I had this problem with stdafx.cpp. Somehow stdafx.cpp got duplicated, so there was a second StdAfx.cpp (mind the different case).
After I removed the StdAfx.cpp everything worked fine!
Using VS 2010.
I use $(IntDir)\%(Directory)\ under C/C++ -> Output Files -> "Object File Name".
I used to have in the same project .c and .cpp files with the same filenames. The files were in folders all over the place and the solutions provided by others created a mess, and folder hell (in my case). Even Release builds would overwrite Debug builds!
A good (not perfect) solution would be to use $(ParentName), but for some reason beyond anyone's grasp it has been removed from later versions of Visual Studio (2015+).
What I use succesfully now is:
$(IntDir)%(Filename)%(Extension).obj
which at least separates .c built object files from .cpp.
I'd like to point out one possible reason for why the ItemType of a .h file would change from C/C++ header to C/C++ compiler:
In the Solution Explorer window of VS (2019 here), right click the project name, choose Add -> New Item;
Select the C++ File (.cpp) template, but type something.h in the name input area, then click OK to add it;
Then you'll encounter the LNK4042 warning if the something.h file be included within more than one .cpp files.
I just overcame a similar error message, and lots more with the procedure below. Symptom: one linker error for every invocation of every function defined in a particular header, plus one at the end of output for every function defined in the header.
Then I remembered that when I had originally created this header, I accidentally had selected "add->new item->c++ file" and though I named it 'whatever.h', it seems Visual Studio considered them both the same kinds of files because of the incorrect action I used to add one. Examining the build output logs made this obvious.
SOLUTION (Using VS Community 2019)
Back up project first (just to be safe).
Right-click the offending header file and select "Exclude from project" (this will not delete them; the VS project will just ignore them).
Do same for the matching .c or .cpp file.
Do Build->Clean on project
Do Build->Rebuild on project
-- there of course will be errors---
Right-click Header Files->Add->Existing Item, then select the .h file
Right-click Source Files->Add->Existing Item, the select the .c or .cpp file
Do Build->Rebuild on project.
This completely cleaned it up for me, relieving me of many irritating linker errors including LNK4042 from the title of this question.
I resolved it changing filenames in my project. There was two files named main.c and main.cpp. I changed one of them and worked.
So the other day I went to compile a VC++ project I am working on and all of a sudden I get errors in almost all of my files saying:
new.h: error C2039: 'set_new_handler' : is not a member of 'std
new.h: error C2039: 'set_new_handelr' : symbol cannot be used in a using-declaration
"new.h" and 'set_new_handler' are not being used in any of my files, so I have no idea how or why these errors are suddenly appearing since they relate to a windows/VS library file.
Would anyone know what I can do to clear this error and compile my code again?
UPDATE After examining the files being included upon compilation, some files are including and some are . The problem is that is being included in afxwin.h and is being included in a third-party library. I honestly have no idea what to do with this problem...no other developers that have played with this code are running into this problem, may it be a settings problem? I am not using precompiled headers.
If I were to hazard a guess, I would say that <new.h> declares set_new_handler in the global namespace and <new> declares it within the std namespace. Some code is including <new.h> and expecting it to act as if it had included <new>. I would suspect either some 3rd party library/header or a precompiled header as suggested by Evan.
You can narrow down the culprit using either /showIncludes or pre-processing a source code file (using /E) and examining the output. I usually use the latter and look at the #line directives in the output file to figure out the include chain.
Good luck.