I'm new C++, I have a dll file called DiceInvaders.dll, in my project, I need to use this library, I'm using visual c++ 2010, I set the Linker Input as DiceInvaders.lib and DiceInvaders.dll, I also copied this dll file to my porject directory, I always got error in this line of code:
m_lib = LoadLibrary("DiceInvaders.dll");
assert(m_lib);
The error is assertion failure. How should I solve this? Thank you in advance.
First you cannot pass the DLL to the linker like you are, it is not a file type that the linker recognizes and cannot be linked that way. When you create the Diceinvaters.dll file the linker will create an import library with the same filename and the extension .lib. It appears this is already being done. That is the library file you should pass to the linker when building any application that uses it.
Second, the Diceinvaders.dll file must be accessible in the DLL search path. This varies slightly depending on which version of Windows you are using but is generally something like the following
The directory the program was loaded from.
The current working directory.
The System directory.
The Windows directory.
The directories that are listed in the PATH environment variable.
Placing the DLL in your project directory is not going to be enough. Instead you should place it in the same directory as the EXE file(s) that have a dependency on it.
Related
Something is wrong with my Visual Studio 2019 project configuration and I have run out of ideas to check. I have 3 native C++ shared libraries (A, B, C) that all sequentially stack on each other. B depends on A. C depends B. I then link all 3 to an executable. So the final stack looks like A->B->C->Executable. All of the libraries and executable live within the same Visual Studio solution. All of the code is mine. The solution file was generated by CMake.
I can set breakpoints and debug into A, B, and the executable just fine. I cannot step into library C because the symbol file will not load. The Modules window says it "Cannot find or open the PDB file." The search path does include the project output folder. When I manually attempt to load the autogenerated library_c.pdb file I see a pop up error stating "A matching symbol file was not found in this folder."
I have tried deleting everything and recreating the environment from scratch. I have compared all the project settings between library C and the other debuggable libraries but found no discernable differences. My internet searches all say how to manually load symbols or indicate that the error is because the symbol don't match. I have not found any that suggest how or why the autogenerated pdb would not match the corresponding lib or dll when built.
Given this situation, what would you investigate next? What could cause the generated symbol file to be mismatched?
EDIT: drescherjm suggested I double check timestamps. Windows Explorer lists the "Date modified" as being identical. However, if I right click on each file and open properties I get an interesting abnormality. The "Created" timestamp of the good working files all have a date and time (HH:MM:SS). The bad library_c.pdb lists a date with no timestamp. Instead of a timestamp it says "XX minutes ago." I'm not sure what this means but it is a difference.
The CMake file for library C (called foo_client here) has this snippet.
add_library(foo::foo_client ALIAS foo_client)
set_target_properties(foo_client PROPERTIES EXPORT_NAME client)
The executable's target name in CMake is foo_client_exec. For a reason unknown to me this triggers a corrupt foo_client.pdb file. By using dbh I dumped all the source files (dbh foo_client.pdb src) referenced in the .pdb file and confirmed the list was missing everything from the foo_client library. However, it somehow referenced files from the executable. Let me repeat that oddity to emphasize it. The exectuable's files were somehow referenced in library's .pdb., foo_client.pdb. I have no idea how the chain of binaries could be propagated backwards from executable back into the library.
If I renamed the executable to anything that did NOT start with "foo_client" as a prefix then the .pdb file was generated correctly and only referenced the foo_client files. It appears that Visual Studio 2019 and/or CMake 3.15 was doing some kind of naming pattern match that caused the source files of the executable to replace the libary's files in the generated .pdb.
Despite the corrupted .pdb file the library performed without issue when linked into any executable. Whatever the root cause of the problem is it appears to be isolated to the generation of the .pdb file. Everything else works as normal as far as I can tell.
I'm working in a Cocos2dx (c++) win 32 project and trying to use sqlite to save the game data. My knowledge of c++ / Visual Studio is very limited right now.
This is part of the code that I'm trying to compile.
#include <sqlite3\include\sqlite3.h>
...
void HelloWorld::SaveAndLoadTest()
{
sqlite3 *pdb = NULL;
sqlite3_open("writablePath", &pdb);
...
}
But when I try to compile the line with the sqlite3_open command I get the following error:
Error 7 error LNK2019: unresolved external symbol _sqlite3_open referenced in function...
I've been trying to find an answer for this many hours. The most similar question I found was this one but I don't understand the answer.
Error: undefined reference to `sqlite3_open'
You need to link the sqlite3 library along with your program:
g++ main.cpp -lsqlite3
I'm new to Visual Studio and I don't understand how to solve this, anyone?
The error LNK2019 means that references are missing probably because a library is mising.
To add sqlite to a MSVC project, you have to make sure that:
the header is included in your source files
sqlite3.dll is in the path or in the directory of the executable
AND that sqlite3.lib is added to the additional dependencies in the VS project (options of the project > Linker > Input > Additional dependencies)
This last point is mandatory, because the lib tells the linker which functions are stored in the dll.
The solution, quite simply, is to link sqlite3 to your project. Libraries need to be linked (via the linker) for you to be able to use them. Head over here and download the pre-compiled binaries for your platform of choice (in this case, Win32). You may also choose to compile sqlite3 from source. You should end up with a .lib file. Go to Project -> Configuration Properties -> Linker -> General -> Additional Include Directories and add the path to your library file to it. Then go to Linker -> Input -> Additional Dependencies and put in sqlite3.lib.
And remember that you must build sqlite3.lib from file SQLite3.def:
Download source from source (https://www.sqlite.org/download.html)
For example: source https://www.sqlite.org/2022/sqlite-amalgamation-3390300.zip
Or download binary from binary
For example: binary https://www.sqlite.org/2022/sqlite-dll-win64-x64-3390300.zip
Extract both archives to the same directory
Open Developer Command Prompt for VS 2017 by typing Developer Command in Windows Search
Go to directory where you've extracted source code and binary files (via opened cmd)
Run lib /DEF:sqlite3.def /OUT:sqlite3.lib /MACHINE:x64
(Remember if win32, replace "MACHINE:x64" by MACHINE:x86)
I downloaded jpeglib-9a. In Visual studio (2012) command prompt I typed this:
nmake /f makefile.vc setup-v10
It created several files and one of them was named "jpeg.sln" which I opened in visual studio (updated to 2012 version) and built. After that, I made new project, included this folder "D:\Data\jpeg-9a" and added this folder "D:\Data\jpeg-9a\Release" to linker.
And when I tried to compile my project, this error appeared:
1>LINK : fatal error LNK1181: cannot open input file 'D:\Data\jpeg-9a\Release.obj'
I was looking for that file but couldn't find it anywhere. I also tried compile that library again but "Release.obj" is still missing.
This is the tutorial which I was following
http://www.dahlsys.com/misc/compiling_ijg_libjpeg/index.html
So is there any way how to create that file ?
Thank you.
(if you need additional information, ask me)
SOLVED: ... I cant read properly ...
Thank you bogdan
You don't need to create that file.
The linker is interpreting the D:\Data\jpeg-9a\Release directory name as an input .obj file name. Most likely, this is happening because you added the directory name in the wrong place in the linker configuration property pages. My guess is that you added it under Linker -> Input -> Additional Dependencies; that's not the right place for a directory - that property is supposed to contain a list of .obj and .lib files to be given as input to the linker.
You need to add the directory under Linker -> General -> Additional Library Directories.
I got a library here which uses the Intel Composer XE 2013 and I would like to compile it as a .lib as I am going to use it with another project (It is compiling as application/EXE by default). However, when I set the Configuration Type under Project Defaults under the Configuration Manager in Visual Studio 2012, I get " error LNK1181: cannot open input file" Odd part is that the file it looks for has no file ending. The project contains both C, C++ and ASM code. Does anyone got any experience with this kind of behavior?
Some common causes for error LNK1181 are:
filename is referenced as an additional dependency on the linker
line, but the file does not exist.
A /LIBPATH statement that specifies the directory containing filename
is missing.
To resolve the above issues, ensure any files referenced on the linker line are present on the system.
Use the /LIBPATH option to override the environment library path. The linker will first search in the path specified by this option, and then search in the path specified in the LIB environment variable. You can specify only one directory for each /LIBPATH option you enter. If you want to specify more than one directory, you must specify multiple /LIBPATH options. The linker will then search the specified directories in order.
To set this linker option in the Visual Studio development environment
Open the project's Property Pages dialog box.
Click the Linker folder.
Click the General property page.
Modify the Additional Library Directories property.
If that doesn't help then you can look through these links :
Getting fatal error LNK1181: cannot open input file
You receive a "fatal error LNK1181" error message when you build a
Managed C++ application
Visual Studio: LINK : fatal error LNK1181: cannot open input
file
I solved the issue by renaming the .obj files without their file extension. For example, it was looking for file name "foo", I had "foo.obj" so I renamed "foo.obj" to "foo".
I have a VS 2010 C++ project.
When I try to compile it, it tells me
Error 1 error LNK1104: File "C:\Users\MyUser\Desktop\project1\Debug\mysynth.lib" could not be opened. C:\Users\MyUser\Desktop\project1\subproject\LINK subproject
I have removed all dependencies from Linker->Input->, but it is still looking for the above lib.
Where else could this link be stated?
You can specify additional linker options in the configuration dialog. Look under the Linker | Command Line page. Perhaps the errant lib is specified there. In any case you can see there the command line that is passed to the linker and determine whether or not your lib file is there.
The easiest way to work out where they are coming from is to open up the project file in a text editor and search for the errant lib file. If the problem is in the project configuration, this tactic is guaranteed to succeed.
If you have removed everything from your project settings, and you are not passing the errant lib to the linker command line, then the other place where a lib file may be specified is in code. In a #pragma statement. It would look like this:
#pragma comment(lib, "mysynth")
Look in the properties explorer. Read the MSBuild documentation for the order that they are read. This is the most confusing part of going from VS2008 forward.