Skip to main content
GameDev.net gamedev.net
🔒 Locked

visual studio ignoring some source files

Started by nihilisticod Feb 27, 2008 at 9:38 AM 10 replies 1.6k views
Original Post
nihilisticod
nihilisticod
Is there a way to prevent the visual studio 2003 .NET optimizer from ignoring source files that it believes are completely unused? I have tried disabling some of the optimizer features but they did not seem to work. There may have been lingering intermediate files, but I wondered if anyone knew how to solve this problem offhand? I am working in C++, building a win32 executable project, and have a number of dll-exported functions in a file that are never actually called within my application. However, they can be accessed by using GetProcAddress to locate the function addresses. When built, those functions are not exported (according to a PE viewer). It seems that the only way to get them to 'exist' is to place some variable or function in that same source file that the program actually uses when following an ordinary path. EDIT: many other functions in other files are correctly exported. It is simply a matter of visual studio skipping over some source files that it thinks contain no used code. [Edited by - nihilisticod on February 27, 2008 11:38:19 AM]
Marineio
Marineio
__declspec(dllexport) on MSVC?

otherwise dont forget the .def file! :D
nihilisticod
nihilisticod
I do use dllexport. Other functions are correctly exported. See my edit.
bakery2k1
bakery2k1
Quote:
Original post by nihilisticod
It is simply a matter of visual studio skipping over some source files that it thinks contain no used code.


Visual Studio shouldn't "skip" source files. Are you sure you have not explicitly excluded the files from your build? Check => Right-Click => Properties => Configuration Properties => General => Excluded from Build.

Alternatively, can you call the functions from within your application? i.e. are the functions being built, but not exported, or are they not being built at all?
nihilisticod
nihilisticod
Quote:
Alternatively, can you call the functions from within your application? i.e. are the functions being built, but not exported, or are they not being built at all?

That's just the thing. If I call just one of the functions in the file in my other code, ALL of the functions in the file get exported correctly. If I call none of them, then NONE of them get exported. I can only assume that they are not being built in at all in that case. wouldn't you agree? I could just stick a dummy function in and call it, but I don't think I should have to do that.
SiCrane
SiCrane
What does your linker command line options look like?
nihilisticod
nihilisticod
in debug mode... I have basically all defaults besides my extra libs.

/OUT:"../bin/debug/PG.exe" /INCREMENTAL:NO /NOLOGO /DEBUG /PDB:"../bin/debug/PG.pdb" /SUBSYSTEM:WINDOWS /MACHINE:X86 vcheckappd.lib analysisd.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
bakery2k1
bakery2k1
Quote:
Original post by nihilisticod
I can only assume that they are not being built in at all in that case. wouldn't you agree?


We shouldn't have to assume. All we know is that these functions are not being exported. To find out whether they are actually built and included in your exe, try running "dumpbin /disasm" on the exe and search the output (e.g. using grep) for the name of one of the functions. Note that the name displayed by dumpbin will be "decorated" (aka "mangled").

Also, try linking with the /verbose command-line option and see if any relevant messages are output.
nihilisticod
nihilisticod
where does one get dumpbin?

None of the verbose linker messages seem relevant.
SiCrane
SiCrane
dumpbin is one of the executables that ships in the bin directory for MSVS installs. Run vcvars32.bat to get it in your path for a command prompt.
bakery2k1
bakery2k1
Quote:
Original post by nihilisticod
where does one get dumpbin?


If you're running Visual Studio .NET 2003, go to Start => Programs => Visual Studio .NET 2003 => Visual Studio .NET Tools => Visual Studio .NET 2003 Command Prompt. This will give you a command window with the environment set up to use dumpbin, among other tools.
nihilisticod
nihilisticod
Neat tool, thanks. I used dumpbin it to look at a lot of build files and realized my build configuration wasn't exactly as I said it was. sorry.

The functions in question were not the ones in the exe project itself, but are defined within a source file in my own lib project, which is linked into the final executable.

If I add an empty source file with only unreferenced/exported functions to the actual executable project, it produces an exe with correctly exported functions from that file. However, when those exported/unreferenced functions are within the .lib, they do not wind up in the final executable.

They symbols for the functions in question ARE in the .obj of the source file where they are defined. the symbols ARE also in the .lib file compiled from those obj files. But the functions do NOT make it into the final exe (while all of the others from the same lib do).

I have tried adding /OPT:NOREF to the linker of the executable project and doing a full clean/rebuild of everything to no avail.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.