LNK1136 invalid or corrupt file - c++

Trying to use .lib in Visual c++ CLR project.
This .lib is built in c++ builder 5, i have .lib file and .hpp file.
created visual c++ -> CLR -> class library project.
In properties following fields are added,
C/C++ -> General ->
Additional include directories = C:\Users\D2\source\repos\CLR\CLR\LIB
Linker -> Additional include directories = C:\Users\D2\source\repos\CLR\CLR\LIB
Input -> Additional Dependencies = lib0.lib
C:\Users\D2\source\repos\CLR\CLR\LIB, This location contains .hpp, .lib, .dll files.
And Builded,
Linker error is coming, LNK1136 invalid or corrupt file
As this error says, I checked no other application is using this library and specified the correct library name and path. I'm confused with this corrupt file word because the same library is working with c++ builder 5.
please give suggestions.

Related

How to link mysqlcppconn.lib to a c++ project

I'm trying to use the mysqlcppconn.lib in my c++ project. However, when I put use functionality from the library I get an error:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _mysql_init#4 referenced in function "public: void __thiscall Achievement::set(void)" (?set#Achievement##QAEXXZ) zombie C:\Users\jorda\OneDrive - Limerick Institute Of Technology\College\Final Year Project\Achievement_Libary\Copy - Copy\zombie\Achievement.obj 1
The code I'm using:
MYSQL* conn;
MYSQL_ROW row;
MYSQL_RES* res;
conn = mysql_init(0);
The errors seems to come from the mysql_init(0);
I've tried both the 32 and 64-bit version of the library but both give the same error. I'm not sure if I need to put some dlls inside the executable directory. I've tried putting libssl-1_1.dll & libcrypto-1_1.dll from both the 32 bit and 64-bit files as that's what one tutorial did however this did not work.
Would anyone know the process of trying to use the C++ connector in a visual studio project? Any help is appreciated. Here are the lib and input paths from the Linker
Would anyone know the process of trying to use the C++ connector in a visual studio project?
I suggest you could try the following steps:
1,Add the path to the header file to the Additional Include Directories(property - >c/c++ -> General -> Additional Include Directories)
2,Add the path to the .lib file to the Additional Library Directories (property -> linker -> General -> Additional Library Directories)
3,Add the name of the .lib file with its extension to Additional Dependencies (property -> linker -> input -> Additional Dependencies)
I suggest you could try to check if the file is in the location that you specified, or if you have provided the correct library path. And you couldn't mix 32 bit and 64 bit. Please make sure you're linking in 64-bit libraries with the 64-bit application, or change your app to 32-bit and link with the 32-bit libraries.

1>LINK : fatal error LNK1104: cannot open file

I am trying to add external libraries to my project but I always get this error
LINK : fatal error LNK1104: cannot open file 'C:\Users\Lubdmila\Desktop\OpenMAT-1.3.4\lib\x86.obj'. I was following these instructions:
(I was given these instructions )
The LpSensor library contains classes that allow a user to integrate LPMS devices into their own applications. The standard library is a Windows 32-bit C++ library for MS Visual C++ (express) 2010. Should you require a binary of the library to work on another operating system or 64-bit applications, please contact LP-RESEARCH.
Compiling applications that use the LpSensor library requires the following components:
Header files (usually in C:/OpenMAT/include):
LpmsSensorManagerI.h Contains the interface for the LpmsSensorManager class.
LpmsSensorI.h Contains the interface for the LpmsSensor class
ImuData.h Structure for containing output data from a LPMS device
LpmsDefinitions.h Macro definitions for accessing LPMS
DeviceListItem.h Contains the class definition for an element of a LPMS device list
LIB files (usually in C:/OpenMAT/lib/x86):
LpSensorD.lib LpSensor library (Debug version)
LpSensor.lib LpSensor library (Release version)
DLL files (usually in C:/OpenMAT/lib/x86):
LpSensorD.dll LpSensor library (Debug version)
LpSensor.dll LpSensor library (Release version)
PCANBasic.dll PeakCAN library DLL for CAN interface communication (optional).
ftd2xx.dll The FTDI library to communicate with an LPMS over USB.
To compile the application please do the following:
Include LpmsSensorManagerI.h.
Add LpSensor.lib (or LpSensorD.lib if you are compiling in debug mode) to the link libraries file list of your application
Make sure that you set a path to LpSensor.dll / LpSensorD.dll, PCANBasic.dll (optional) and ftd2xx.dll so that the runtime file of your application can access them.
Build your application.
I am using MS Visual Studio 2010 express 32-bit.And this is what I have done:
1) Project/Properties/Configuration Properties/C/C++/General/Additional Include Directories path---C:\Users\Lubdmila\Desktop\OpenMAT-1.3.4\include
2)Project/Properties/Configuration Properties/Linker/General/Additional Library Directories---C:\Users\Lubdmila\Desktop\OpenMAT-1.3.4\lib\x86
3)Project/Properties/Configuration Properties/Linker/Input/Additional Dependencies---C:\Users\Lubdmila\Desktop\OpenMAT-1.3.4\lib\x86
4) Project/Properties/Configuration Properties/VC++ Directories/General/ Include Directories path---C:\Users\Lubdmila\Desktop\OpenMAT-1.3.4\include
5) include "LpmsSensorManagerI.h"
I have tried to add quotes around the paths but it did not help.I have no clue why I am getting this error.
Does anyone know what I am doing wrong?
Thank you
It seems you have mistakenly added
" C:\Users\Lubdmila\Desktop\OpenMAT-1.3.4\lib\x86 " to the additional dependencies under
" Properties/Linker/Input/Additional Dependencies- "
In this section you should simply list your additional library names, such as
" LpSensor.lib "
The path " C:\Users\Lubdmila\Desktop\OpenMAT-1.3.4\lib\x86 " is already set in " Properties/Linker/General/Additional Library Directories--- " for the linker to look for.
It works now. I created a new project did the same steps but I changed step 3 as harry 268 advised and then I added path to dll files.
Here's the link to the solution: How to add a path to dll files
Visual Studio: how to set path to dll?
In my case I had fatal error LNK1104: cannot open file 'C:\Users\..\proj.exe'
in order to solve this issue, I just copied whole proj folder and renamed it. and that is working now

Visual Studio Additional Include Paths?

I'm working on an existing Visual Studio 12 "Solution" from another team..
In one of its "project"s,, there's a header file that includes a file from another static library projecet..
So Lets say the solution structure looks something like this:
Project A (Static Library Project)
\__ someFile.h
Project B (Static Library Project)
\__ someLibrary.h
In someFile.h,
...
#include "someLibrary.h"
...
and this loads the library successfully.. BUT this is strange because the path to someLibrary.h is NOT SPECIFIED anywhere in Project A's settings!!
I've checked Configuration Properties => VC++ Directories => Include Directories but path to someLibrary.h is NOT specified here..
Since Project A is a static library with NO cpp files (has only header files), It does not have a Configuration Properties => C++ => Additional Include Directory Option at all... (It only has the Librarian option)
And of course someLibrary.h is not in the same directory as someFile.h.
Finally, in Project A's Common Properties, Project B is not referenced either...
So my question is : How the hell does someFile.h know where someLibrary.h is?
How is it including it??
Is there any other places in project settings/etc where additional include directory can be specified..?
UPDATE:
when I right click on the #include statement and click "Open Document 'someLibrary.h'",
I do see a following VS error box:
File 'someLibrary.h' not found in current source file's directory or in build system paths.
Nevertheless,, there is NO build error, and Project A uses someLibrary.h with no problem!!

Unresolved external when trying to use .lib/.dll

I am trying to add ANN(open source k-d tree for fast nearest neighbor searching) to my VC++ project. I followed the manual and completed every step:
include the .h files
copy the .lib file, add its location to the linker additional directory
copy the .dll file, set location to environmental variable PATH, and import it in my project
I still get 24 "unresolved external..." errors. The library seems to be widely used and not supposed to be wrong, wondering what else do I need to do to use it?
Thanks guys!
The "unresolved external" error comes because the linker is not finding the "lib" files. The DLL files are only found during run time, not link time.
Do you set the names of the lib files in the project's Properties?
Configuration Properties -> Linker -> Input -> Additional Dependencies
Enter the filenames of the all the lib files, separated by spaces. If they are in your Project folder, use something like
$(ProjectDir)Foobar.lib
have you set path of lib correctly?
you can use lib file along with its path in
on Configuration Properties -> Linker -> Input -> Additional Dependencies
or
just give lib file name in
Configuration Properties -> Linker -> Input -> Additional Dependencies
and lib path in
Configuration Properties -> Linker -> General -> Additional library directories

Visual Studio: Include .h or .cpp in two-project solution

I have a Visual Studio solution containing 2 project: main project and test (via googletest). In main project I have myclass.cpp and myclass.h files. When I'm trying to compile test project, there are bunch of LNK2019 errors when I include "myclass.h" in my test.cpp file, but everything works fine if I include "myclass.cpp" instead. Is that normal? As far as I know, including of .cpp files is not recommended and generally can be avoided. Any suggestions?
It's normal. If you have 2 projects, 2 binaries will be generated.
Don't include the cpp file.
Instead, link the binaries together.
main project - generates .lib file and either .dll or .exe.
test project - includes header from main. You need to add the .lib generated by main in the additional dependencies of the test project. Somewhere in the Project Settings - Linker Options - Additional Dependencies.
You can generate both .exe and .lib file from a single project. To do this you set:
exe in Linker -> General -> Output File
lib in Linker -> Advanced -> Import Library
You may also need to mark exported functions with __declspec( dllexport ) in the .exe project (see docs), otherwise compiler won't generate a .lib file.
Steps to Use Classes form another project (Add header and solver linker errors)
1) To be able to add the header from another project, first go to "Properties > c++ > General > Additional Include Directories" and add the directory that contains the header. Now you will be able to add the header of the class from the other project, but running the project will still cause Linker Errors.
2) Add __declspec(dllexport) before the class you are using for the other project. This can be added in the header file of that class. This should be added right before the function or variable or class name. Now you will get a lib file. (if placed in wrong place, you can get this warning: https://msdn.microsoft.com/en-us/library/eehkcz60.aspx)
3) "Properties > Linker > Additional Library Directories". Specify the location of the lib file that is generated.
4) "Properties > Linker > Input > Additional Dependencies”: Add the name of the lib file.