linking problems (invalid or corrupt file)  
Author Message
Jacek Jablonski





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

Hello experts!
I was testing compilation programs with dlls. So I have created simple dll with header:
int sum(int size)
{
return size*2;
}

And I have compiled it. I have also created simple console application using this library. In project options I have added headers path and libs path, but I have linking errors:

Linking... C:\Documents and Settings\Jacek\Moje dokumenty\Visual Studio 2005\Projects\mylib\release\mylib.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x278

Please help, I don't understand this error and I don't know what to do.
Greetings


Visual C++16  
 
 
Peter Ritchie





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

Are you using Visual C++ 2003 or 2005.

If 2005, try right clicking the mylib project in the solution explorer and selecting "clean", or (if 2003) try a rebuild of the solution. If you still have the same problem, post the build output and someone might be able to offer the guidance.



 
 
Jacek Jablonski





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

I am using VS 2005. After cleaning, problem still remains.
------ Build started: Project: middle, Configuration: Release Win32 ------
Compiling...
stdafx.cpp
Compiling...
test.cpp
Linking...
C:\Documents and Settings\Jacek\Moje dokumenty\Visual Studio 2005\Projects\mylib\release\mylib.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x278
Build log was saved at "file://c:\Documents and Settings\Jacek\Moje dokumenty\Visual Studio 2005\Projects\test\test\Release\BuildLog.htm"
test - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

 
 
Peter Ritchie





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

I don't see anywhere in your build log that mylib is being built.

 
 
Jacek Jablonski





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

Mylib is build in other project. Here is log:
------ Build started: Project: mylib, Configuration: Release Win32 ------
Compiling...
stdafx.cpp
Compiling...
mylib.cpp
Linking...
Generating code
Finished generating code
Creating manifest...
Build log was saved at "file://c:\Documents and Settings\Jacek\Moje dokumenty\Visual Studio 2005\Projects\mylib\mylib\Release\BuildLog.htm"
mylib - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

 
 
Peter Ritchie





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

Your middle project seems to be looking for the mylib dll in a different directory than the one it was built to. middle is complaining about "C:\Documents and Settings\Jacek\Moje dokumenty\Visual Studio 2005\Projects\mylib\release\mylib.dll" but it appears mylib is being output to "c:\Documents and Settings\Jacek\Moje dokumenty\Visual Studio 2005\Projects\mylib\mylib\Release\".

You might want remove the reference to mylib.dll and re-add it.



 
 
Jacek Jablonski





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

After changing that, still the same error.

 
 
Peter Ritchie





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

With assemblies that are corrupt or invalid, you should get warnings in the error list when you load your solution/project. If a referenced DLL is invalid you should also see an exclamation warning sign on the icon for the particular reference in the solution explorer References branch. Do you get either of those when you load your solution

 
 
Jacek Jablonski





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

I am doing that in this way: I ma creating very very simple dll file. Than I create new project and to this project I add header file from this dll. In project options I set additional LIB paths, so linker can find this dll.

References branch is empty.O_o

 
 
Louis Lafreniere





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

The problem is that you are trying to link the dll directly to your application. An import lib (mylib.lib) should have been created when you linked the dll. That's the file you need to link in, not mylib.dll. That lib will cause your exe to load to your dll at runtime.

-- Louis Lafreniere



 
 
Jacek Jablonski





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

Unfortunatelly, there is no mylib.lib file in project directory. I am creating dlls in 2 ways.
1 way: new project-> console application than in project options I set dll.
2 way: new project-> console application and there I set dll.
Neither of these methods makes mylib.lib file.

 
 
Peter Ritchie





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

If you want to generate a lib file for you mylib project, make sure that "Import Library" is not empty in Project Properties/Linker/Advanced.

Usually this is set to $(TargetDir)$(TargetName).lib.



 
 
Jacek Jablonski





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

It is set.
But command line doesn't contains /IMPLIB

/OUT:"C:\Documents and Settings\Jacek\Moje dokumenty\Visual Studio 2005\Projects\ezio\Release\ezio.dll" /INCREMENTAL:NO /NOLOGO /DLL /MANIFEST /MANIFESTFILE:"Release\ezio.dll.intermediate.manifest" /DEBUG /PDB:"c:\documents and settings\Jacekszefu\moje dokumenty\visual studio 2005\projects\ezio\release\ezio.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib

 
 
Louis Lafreniere





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

There seems to be a bug in the property sheet... Go to the implib setting and touch the implib name (add a space at the end). When I tried that, the /IMPLIB appeared on the link command line.

-- Louis Lafreniere



 
 
Jacek Jablonski





PostPosted: Visual C++ General, linking problems (invalid or corrupt file) Top

.lib file stil doesn't want to appear. But /IMPLIB appeared on the link command line:
/OUT:"C:\Documents and Settings\Jacek\Moje dokumenty\Visual Studio 2005\Projects\mylibrary\Release\mylibrary.dll" /INCREMENTAL:NO /NOLOGO /DLL /MANIFEST /MANIFESTFILE:"Release\mylibrary.dll.intermediate.manifest" /DEBUG /PDB:"c:\documents and settings\szefu\moje dokumenty\visual studio 2005\projects\mylibrary\release\mylibrary.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /IMPLIB:"c:\documents and settings\Jacek\moje dokumenty\visual studio 2005\projects\mylibrary\release\mylibrary.lib" /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib