Wumpf / IncludeToolbox

Visual Studio extension to format, prune, and inspect include directives.
https://marketplace.visualstudio.com/items?itemName=Wumpf.IncludeToolbox
MIT License
51 stars 22 forks source link

Trial & Error Include Removal ignores linker error. #65

Closed Donaldpherman closed 5 years ago

Donaldpherman commented 5 years ago

I have the declaration of a function in the global namespace in a header file "aName". The file with definition include the #include "aName.h" header and builds. Another project call the function and builds OK.

// aName.h
__declspec(dllexport) func(*void,**void,int,int);
// differentName.cpp
#include "aName.h"
func(*void,**void,int,int){
  //some implementation.
}

//differentProject.cpp
//calling the function func.
func(arg,arg2,arg3,arg4);

When I run Trial & Error Include Removal on differentName.cpp it removed the #include "aName.h" and give me the message Successfully removed #include: 'aName.h'
Removed 1 #include directives from 'differentName.cpp'

When I try to build the solution I get a linker error. error LNK2019: unresolved external symbol "declspec(dllimport) void cdecl func

Wumpf commented 5 years ago

This is by design. As the name suggests "Trial & Error Include Removal" only tries removing an include and tries if the file in question still compiles. Judging from your error, unlike what you describe your header seems to declare the function with __declspec(dllexport) whereas your duplicated predeclaration (why?) does not, leading the file to compile fine but no longer exporting the symbol

Donaldpherman commented 5 years ago

I upgraded my OP a bit. I don't have a duplicate declaration.

Wumpf commented 5 years ago

In your previous description you had, but the important problem is of course still the same: There is nothing preventing aName.h from being removed but then you loose the dllexport specifier since you didn't repeat that for the function defintion