How do I reference a DLL in a VC++ project - visual-c++

I have a C++ driver I'm trying to compile, and it has this line in the code:
#import "msado15.dll" no_namespace rename("EOF", "EndOfFile")
But when I compile the project, I get the error:
Error 1 fatal error C1083: Cannot open type library file: 'msado15.dll': No such file or directory
I have the DLL, but where do I put it so that the compiler can see it?

You can place the DLL in the same path as the referencing file (.h) as you have done, alternatively you can modify the additional include paths for the LIB section of your project(s). In VC++ this will be:
Project | Properties | Configuration Properties | Linker | General | Additional Library Directories
This method can be useful if you are centralizing third party dependencies and you don't want to be forced to keeping the referenced file (.h) and DLL in sync via the same path.
See this MSDN link for further details.

For VC++2010(VS2010): the compiler is not able to see the msado15.dll
which is located at C:\Program Files\Common Files\System\ado
Go to Project | Properties | Configuration Properties | VC++ Directories
and add the following at executable directories
$(CommonProgramFiles)\System\ado;
You should be fine

This may be a little out of date for most people, however - for Visual Studio 2008, for a particular
Project |
Configuration Properties |
C/C++ |
Additional Include Directories |
Select and click on the ellipsis (...).
Add the directory
C:\Program Files\Common Files\System\ado
and move it to the bottom of the list using the arrows.

OK, found it by reading the documentation. I just had to put it in the same folder as the referenced file (which was in a different location to the project source code).

You need to have library files and function definition headers to do this. If you happen to don't have them, you would try dynamic loading of DLL using LoadLibrary and GetProcAddress, pointers for linking functions.

Try to set "Delayed DLL loading" (or an option similar) in 'Project Properties'->'Linker'->'input' section of your VC++ project.

Related

Building SQLite DLL with VS2015

I'm trying to build SQLite as a DLL from sources. In the the "How to" section of the website, they give a simple command line to build it :
cl sqlite3.c -link -dll -out:sqlite3.dll
When I try this command, I get the DLL but not the ".lib" file. With the DLL only I cannot use SQLite inside another dev project. Without the .lib file, there are some symbols missing.
here are some notes i made a while ago on creating a sqlite3.lib file using the contents of sqlitedll-X_X_X.zip (and some other files). This approach might differ from your intended approach - but it may get your project started - I hope it helps.
create \tmp folder in your project directory
find the following 3 files (on the web) and then copy them into the \tmp directory: lib.exe, link.exe, mspdb80.dll
from the latest sqlitedll-X_X_X.zip file (i used: http://www.sqlite.org/sqlitedll-3_7_3.zip) copy sqlite3.def and sqlite3.dll to \tmp directory
open command line (terminal) and navigate to \tmp directory
create .LIB file by typing:
LIB /DEF:sqlite3.def /MACHINE:X86
copy the newly created sqlite3.lib file to your project directory
make sure that the following files are in the project directory:
sqlite3.h (from: http://www.sqlite.org/sqlite-amalgamation-X_X_X.zip)
sqlite3.dll (from: http://www.sqlite.org/sqlitedll-X_X_X.zip)
also
add the sqlite3.h file to the project
make sure that the linker can see sqlite3.lib
For those trying to do this with CMake, and assuming that you are building from amalgamation sources, to produce the .lib file when building a shared variant on Windows you need to add a compile definition SQLITE_API=__declspec(dllexport), for example:
project("SQLite3"
VERSION 3.39.1
DESCRIPTION "Small, fast, self-contained, high-reliability, full-featured SQL database engine"
LANGUAGES C
)
# ...
add_library(${PROJECT_NAME})
# ...
if(BUILD_SHARED_LIBS)
if(WIN32)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
"SQLITE_API=__declspec(dllexport)"
)
else() # haven't tested that
target_compile_definitions(${PROJECT_NAME}
PRIVATE
"SQLITE_API=__attribute__((visibility(\"default\")))"
)
endif()
endif()
# ...

Where can find x86.obj?

When I debug C++ file of open source, the error message show that:
error 1 error LNK1104: cannot open file 'C:\Program Files\Microsoft DirectX SDK (June2010)\Lib\x86.obj'
The directory of Microsoft Directx sure have no file called 'x86.obj'.
So, what is the x86.obj? Where can I get it?
The platform I use is Visual Studio 2010.
I think the obj file maybe is a combine of .lib file... because in the path, I only see the lib file under the directory of /x86, so I guess:
The C++ use x86.obj, but it just means that it use lib file under /x86 directory.
So, is there any way to let many .lib file turn to one .obj file?
Any advising appreciate!
I have found the solution!
I try to search the text "pragma" all the file, and found what lib the C++ use, and I add it to the linker with whole path like: C:/Program Files/Microsoft DirectX SDK (June 2010)/Lib/x86/dxguid.lib
So, there is no x86.obj file! But if someone face the likely problem, remember to search (crl+F)"pragma", and check what lib you use and add to linker with whole path. Sometimes, the linker can not understand whether the "path" is directory or a lib file, so it occur errors.
Thanks for everyone!

Including DLL's In VC++(VS2010) Project Output

Disclaimer: Am a C# developer trying to understand a few C++ fundamentals
Have created a command line project which has the .lib of a DLL file linked under Linker > Input > Additional dependencies, and also has the location of the header files specified under C/C++ > General > Additional Include Directories. Ran a build and all compiled okay, with the .exe being built in the Debug/Release dir.
Problem is I also expected the .dll file the project depends on to be there (just like when you add a reference in a .Net project) - but it isn't. When launching the .exe it complains that it can't find the DLL. Fair enough, but why didn't the VC++ put the DLL there if it knows it's required?
And is there a "best practice" to ensuring the dependent DLL files are in the output dir, other than manually copying them there? I have a project that will require use of some third-party libraries, and I was hoping the IDE would help me manage them...
Big thanks for any guidance given!
If you create solution which contains exe and dll, all output files are created in $(SolutionDir) Debug or Release subdirectories, and exe runs successfully. Otherwise, you have one of the following options:
Copy Dll in Post-build step to directory where it is available for loading (usually .exe directory)
Add Dll directory to PATH.

How to link a .lib in Visual Studio 2008 C++

I'm finding it really difficult to properly link a .lib file to my C++ Win32 Console Application. Here's my problem.
Just as in this MSDN article, I have developed a MathFuncsLib.lib file.
http://msdn.microsoft.com/en-us/library/ms235627%28v=vs.80%29.aspx
Then, in the MyExecRefsLib Win32 Console App, I want to link to the above file. So, inside MyExecRefsLib folder (same folder where .sln file resides) I created a directory called "LibraryFiles" and placed both MathFuncsLib.lib file AND MathFuncsLib.h file.
Then, in Properties->Linker->Input I added both "MathFuncsLib.lib" and "MathFuncsLib.h" (without full path) and then in Properties->Linker->Additional Library Directories I added the path to my folder "LibraryFiles" which is what pretty much EVERY thread on the web about this problem tells me to do.
But now it gives me the following error:
fatal error C1083: Cannot open the
include file. 'MathFuncsLib.h': No
such file or directory.
What am I doing wrong? Please help.
Note that my code is exactly the same as what's in the above given MSDN link.
To link with a .lib file, you just need to:
right clic on the project name, select Properties
under Properties->configuration properties->C/C++->General item "other include directories" add the path to your .h file
under Properties->Linker->Input add the path and name of your .lib file
And that's it.

fatal error LNK1104: cannot open file 'ATL9ProPS.def'

I have a VC++ project. When i compile the project in VS2008 i get the following linker error:
**Error 1 fatal error LNK1104: cannot open file 'ATL9ProPS.def' **
I have been compiling this same code since a year (with minor changes here and there) now but never saw this error. Also, my project does not refer to any file by name 'ATL9ProPS.def. (I guess this file is part of a project that is save to computer during Visual studio installation)
When i searched for this .def file in my machine i found it in the following location
C:\Documents and Settings\Abi\My Documents\Visual Studio 2008\Projects\ATL9Pro.
But how on earth is this file bothering my project. I have no clue how this is linked to my project. Please help me resolve this.
For details
Project -> Properties -> Configuration Properties -> Linker -> Input
-> Module Definition File -> Replace this with the right def file.
Try my moving that file to a different location or by renaming the file. Also see if there is any path in the Linker -> Additional include directories refers to My Documents/.../Projects folder.
Anand,
Thanks for the response. Not exactly Linker -> Additional include directories but The Linker->ModuleDefenitionFile option was referring to the file name ''ATL9ProPS.def'. I just replaced this with the right def file and it worked. Thanks

Resources