Strange link error while rebuilding in visual Studio 2012 - c++

I have a very strange problem. I have a project in VS2012 that links statically with another lib.
If I build project everything is fine.
However, if I REBUILD the project it will fail with link problems.
The lib is compiled, I do not compile it during the build.
It is no difference if I clean everything or building/rebuilding on top of previous build.
Build works, Rebuild - not!
Can anyone give me at least a clue - what different in those 2 commands? I do not even know how to start investigate the problem.
Supplemental:
To all the people that answered - You are trying to explain me the difference between the build and rebuild. Thank you, but I know it. You ignore the fact that I explained before:
I can completely clean previous results, delete OutDir, delete IntDir, delete everything produced by the compilation. still - Build work, Rebuild not.
In the explained above case - what is the difference between build and rebuild if you build the first time??
The reason I did not posted errors is that those are simply link errors telling me .lib is missing. While it is clearly not.
Here is the example:
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2872): warning RC4005: '_useHeader' : redefinition
1>
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2882): warning RC4005: '_on_failure' : redefinition
1>
1> Creating library D:\p4client\ProAudio\dev_main\ProAudio\XPlatform..\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\Products\WaveShell-DAE.lib and object D:\p4client\ProAudio\dev_main\ProAudio\XPlatform..\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\Products\WaveShell-DAE.exp
1>DefaultSwap.obj : error LNK2019: unresolved external symbol _ASI_UnregisterCustomByteSwapper#4 referenced in function _RemoveByteSwapper
1>DefaultSwap.obj : error LNK2019: unresolved external symbol _ASI_RegisterCustomByteSwapper#8 referenced in function _RegisterByteSwapper
1>PlugInLib.lib(PlugInUtils.obj) : error LNK2001: unresolved external symbol _imp_FicGestalt#8
1>PlugInLib.lib(CDSPProcess.obj) : error LNK2001: unresolved external symbol _imp_FicGestalt#8
1>PlugInLib.lib(CAdaptorPlugIn.obj) : error LNK2001: unresolved external symbol _imp_FicGestalt#8
1>CShellProcessGroup.obj : error LNK2019: unresolved external symbol _imp_FicGestalt#8 referenced in function "public: __thiscall CShellProcessGroup::CShellProcessGroup(void)" (??0CShellProcessGroup##QAE#XZ)
1>CEffectTypeRTAS.obj : error LNK2001: unresolved external symbol _imp_FicGestalt#8
1>PlugInLib.lib(CProcessGroupInterface.obj) : error LNK2001: unresolved external symbol _imp_FicGestalt#8
1>PlugInLib.lib(CProcessGroup.obj) : error LNK2001: unresolved external symbol _imp_FicGestalt#8
Maybe it will help to know that while running Build (Not rebuild) I will get the following warnings:
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2872): warning RC4005: '_useHeader' : redefinition
1>
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2882): warning RC4005: '_on_failure' : redefinition
1>
1> Creating library D:\p4client\ProAudio\dev_main\ProAudio\XPlatform..\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\Products\WaveShell-DAE.lib and object D:\p4client\ProAudio\dev_main\ProAudio\XPlatform..\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\Products\WaveShell-DAE.exp
1>PlugInLib.lib(C321ChipDSP.obj) : warning LNK4099: PDB 'vc110_ib_2.pdb' was not found with 'PlugInLib.lib(C321ChipDSP.obj)' or at 'D:\p4client\ProAudio\dev_main\ProAudio\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\vc110_ib_2.pdb'; linking object as if no debug info
1>PlugInLib.lib(CDSP.obj) : warning LNK4099: PDB 'vc110_ib_3.pdb' was not found with 'PlugInLib.lib(CDSP.obj)' or at 'D:\p4client\ProAudio\dev_main\ProAudio\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\vc110_ib_3.pdb'; linking object as if no debug info
1>PlugInLib.lib(CDSPUtils.obj) : warning LNK4099: PDB 'vc110_ib_4.pdb' was not found with 'PlugInLib.lib(CDSPUtils.obj)' or at 'D:\p4client\ProAudio\dev_main\ProAudio\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\vc110_ib_4.pdb'; linking object as if no debug info
Thanks!

Build means compile and link only the source files that have changed since the last build, while Rebuild means compile and link all source files regardless of whether they changed or not.
Build is the normal thing to do and is faster. Sometimes the versions of project target components can get out of sync and rebuild is necessary to make the build successful. In practice, you never need to Clean.

'Build' will do an incremental build, basically going through each project in your solution, see if there has been a change since the last build, and if there is, build it again.
'Rebuild' will perform a clean on everything and build everything from scratch.
Edit: A more detailed answer link

If your static lib is another project in the same solution as the project that links to the lib, then you need to set a dependency between the two projects so that the build process will build the lib first and the other project second.
To do this, right-click on the Solution abd choose "Project dependencies" from the pop-up menu.

I am not sure if it is related. But you may want to check this thread (the symptom is reversed from yours though...):
VS2010 Unresolved External Symbol errors on build (but not rebuild)

Related

Unresolved external symbol _glfwInit due to 32-bit/64-bit mismatch

How do I link the library in a way that visual studio 2015 can actually see it?
Here's a few screenshot of my folders:
glfw3, glfw3/include/glfw/, glfw3/lib
I've attempted to link these folders into visual studio, under "vc++ directories => include/library directories as such: include, library
also linking the same to my project directly, under linker => input => additional dependencies
to me, that seems like everything is correct (this is how it was in the tutorial i am following, learnopengl.com)
note: I am also doing the same with the GLAD library, which that has a .c file that I put directly into my sources, along with the header files linked the same way as with GLFW.
but despite trying to run this code:
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main() {
glfwInit();
return 0;
}
it will always return this error, or similar ones:
1>------ Build started: Project: opengl_test, Configuration: Debug Win32 ------
1> main.cpp
1>main.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function _main
1>C:\Users\Honza\Desktop\C++ programs\lib\glfw3\lib\glfw3.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'
1>c:\users\honza\documents\visual studio 2015\Projects\opengl_test\Debug\opengl_test.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I'm guessing there is something wrong with how I linked the libraries. I am willing to literally re-install visual studio if I have to, just please give me some possible solutions. I want to start learning opengl but all this jazz with linking libraries is leaving me frustrated and confused.
EDIT: The problem here was that I was using 64-bit GLFW binaries instead of the 32-bit ones, and compiling in 32-bit. I've fixed that, and now I get even more errors:
1>------ Build started: Project: opengl_test, Configuration: Debug Win32 ------
1>libglfw3.a(init.c.obj) : error LNK2019: unresolved external symbol ___chkstk_ms referenced in function __glfwInputError
1>libglfw3.a(init.c.obj) : error LNK2019: unresolved external symbol _vsnprintf referenced in function __glfwInputError
1>MSVCRTD.lib(vsnprintf.obj) : error LNK2001: unresolved external symbol _vsnprintf
1>libglfw3.a(context.c.obj) : error LNK2019: unresolved external symbol _sscanf referenced in function __glfwRefreshContextAttribs
1>MSVCRTD.lib(vsnprintf.obj) : error LNK2001: unresolved external symbol __vsnprintf
1>C:\Users\Honza\Documents\Visual Studio 2015\Projects\opengl_test\Debug\opengl_test.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
You write that you tried to link "these folders", while in fact, you need 2 separate things in order to use a function from a static library.
Use the proper header file so compilation succeeds. From the error you quoted, compilation went well. The program knows there is an external function named _glfwInit.
Link to the specific library (.lib file). Looks like you placed a path of a folder and not the full path of the .lib file.
Under Linker => input => additional dependencies, place the full path of the gfw3.lib file.
I faced the same problem while following learnopengl.com, The issue is that you need to rebuild glfw library with cmake again,
but this time when you choose visual studio 2015 or whatever for your generator for this project, you must also choose: OPTIONAL PLATFORM FOR GENERATOR -> x64
you can make sure that every thing is OK when you build glfw inside Visual Studio and the platform that appears is x64

MSVC 2015 only provides me with linker error

I am working on a solution with 100+ files. I am using MS Visual Studio 2015 Pro. Compiling it is fine, problems come at link stage.
LINK complains on one of the project's library but only gives me the error number.
The command line (simplified) used is the following:
LINK.exe /NOLOGO /MANIFEST /IMPLIB:C:\\MySolution\\myownlib.lib -LARGEADDRESSAWARE -subsystem:console -MACHINE:X86 -DEBUG -INCREMENTAL /DLL File1.cpp.1.o File2.cpp.1.o File3.cpp.1.o File4.cpp.1.o /OUT:C:\\MySolution\\myownlib.dll
The only output I get is the following:
File1.cpp.1.o : error LNK2005:
File2.cpp.1.o : error LNK2005:
File3.cpp.1.o : error LNK2005:
File4.cpp.1.o : error LNK2005:
File1.cpp.1.o : error LNK2001:
File2.cpp.1.o : error LNK2001:
File3.cpp.1.o : error LNK2001:
File4.cpp.1.o : error LNK2001:
I cannot find any clue as to why the linker does not complains with the duplicated symbols nor the unresolved ones. Since the lib owns more than 80 objects, and nearly all of them is listed, finding the erroneous symbol(s) is like looking for a needle in a haystack!
EDIT : I do not compile using the IDE, I use the developer command prompt to build. Migrating the project in Visual Studio is not frankly possible as the program I am working on has never been imported under Visual Studio, we only use the compiler/linker. Moreover, a colleague of mine working on the project does not experience such troubles. It seems that something is going on under my environment...
EDIT 2 : Full installation repair fixed the problem.

CUDA 6.5: error MSB3191 Unable to create directory and LNK2001 Unresolved External symbol

I am running CUDA 6.5 on Visual Studio 2013 x64.
I have a VC++ static library project named MyLib which is linked with MyClient x64 console executable project. I added CUDA 6.5 build customization to both the projects. In addition, I goto Configuration Properties -> CUDA C/C++ and have set “Target Machine Platform” as 64-bit for these two projects as I want to compile them for x64 platform
I added MyCUDACode.cpp and MyCUDACode.h files to MyLib project and marked their item type as CUDA C/C++ instead oc C/C++ compiler. MyCUDACode.cpp has number of functions which call CUDA API functions. Also, MyCUDACode.h references the cuda.h and cuda_runtime.h files.
MyClient is linked with MyLib. I now get two compilation errors:
First error in compiling MyLib which says a Unable to create directory
Second, I get unresolved external symbol errors while linking
MyClient with MyLib. Here is the log output:
------ Build started: Project: MyLib, Configuration: Release x64 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA 6.5.targets(412,9): error MSB3191: Unable to create directory "x64\Release\D:\github\src\helpers\". The given path's format is not supported.
2>------ Build started: Project: MyClient, Configuration: Release x64 ------
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaGetDeviceCount
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaDeviceCanAccessPeer
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaGetDeviceProperties
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaSetDevice
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaDeviceDisablePeerAccess
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaDeviceReset
2>MyLib.lib(MyCUDACode.obj) : error LNK2001: unresolved external symbol cudaDeviceEnablePeerAccess
2>C:...\visual studio 2013\Projects\Prj\x64\Release\MyClient.exe : fatal error LNK1120: 7 unresolved externals
I have tried both release and debug modes but I get same error.
I am just reproducing the steps to resolve the errors:
To resolve the error(temporary workaround): MSB3191: Unable to create directory The given path's format is not supported., simply copy Cuda cu and cuh files to Visual studio project folder.
[UPDATE]: I recently found a better solution for the issue MSB3191: Unable to create directory The given path's format is not supported.. This fix works without need to move around the cu files to the VS project folder. For this, open the file "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA 6.5.targets", and move to the offending line(412 in this case). This line contains following xml section:
<MakeDir
Condition="'%(CudaCompile.ExcludedFromBuild)' != 'true'"
Directories="%(CudaCompile.DepsOutputDir)" />
As you can see, this is a sort of directive which tells the build system to make a folder for the cuda files being compiled. The property used for folder name is CudaCompile.DepsOutputDir. Now open the file: "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA 6.5.props". This props file defines values of the properties used in targets file. Now search for word DepsOutputDirin this props file. There are only XML section which defines and refers to this keyword is:
<!-- Miscellaneous -->
<DepsOutputFile>%(Filename)%(Extension).deps</DepsOutputFile>
<DepsOutputDir>$(IntDir)%(RelativeDir)</DepsOutputDir>
<DepsOutputPath>%(DepsOutputDir)%(DepsOutputFile)</DepsOutputPath>
Now, to finally fix the MSB3191 issue, simply remove the variable %(RelativeDir) from above xml section and save the props file (this would require administrative privileges)
To resolve the error: LNK2001: unresolved external symbol, follow the Settings for Linker section in this post

Why am I getting error LNK2001 when linking to zlib.lib?

I'm working on a project that already contains the gzip library as follows:
zlib\zlib.h
zlib\zlib.lib
zlib\zconf.h
I would like to use the gzip functions from this .lib but am getting the following errors:
Compress.cpp
Linking...
Compress.obj : error LNK2001: unresolved external symbol _gzclose
Compress.obj : error LNK2001: unresolved external symbol _gzerror
Compress.obj : error LNK2001: unresolved external symbol _gzwrite
Compress.obj : error LNK2001: unresolved external symbol _gzopen
.\Debug/files.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
The link settings include:
Object/library modules: zlib.lib
Project Options:
zlib.lib
In the file using the gzX() functions, it
#include "zlib/zlib.h"
What else needs to be done here to use these functions?
Thank You.
EDIT: Using Visual Studio 6.0 C++
EDIT2: It turned out the static library I was using had the gz() functions taken out of them. The header file still had them which was misleading.
I grabbed the one off here to get zlib to build in windows. If you did the same, you may have forgotten to #define ZLIB_WINAPI before including zlib.h
you also need to add zlib.lib to your project's libraries:
Project properties->Linker->Input->Additional Dependencies.
When the build stops, ctrl-click on the URL to see the more verbose form of the log and check the actual command line passed to the linker. That at least will tell you whether the option to link against zlib is being respected. You may get other useful diagnostic output. One possibility could be that the architecture is different (eg you're building x64 but the lib is x86)
It turned out the static library I was using had the gz() functions taken out of them. The header file still had them which was misleading.

fftw in Visual Studio?

I'm trying to link my project with fftw and so far, I've gotten it to compile, but not link. As the site said, I generated all the .lib files (even though I'm only using double precision), and copied them to C:\Program Files\Microsoft Visual Studio 9.0\VC\lib, the .h file to C:\Program Files\Microsoft Visual Studio 9.0\VC\include and the .dll to C:\windows\system32.
I've copied the tutorial program, and the exact error I am getting is:
1>hw10.obj : error LNK2019: unresolved external symbol __imp__fftw_free referenced in function "bool __cdecl test(void)" (?test##YA_NXZ)
1>hw10.obj : error LNK2019: unresolved external symbol __imp__fftw_destroy_plan referenced in function "bool __cdecl test(void)" (?test##YA_NXZ)
1>hw10.obj : error LNK2019: unresolved external symbol __imp__fftw_execute referenced in function "bool __cdecl test(void)" (?test##YA_NXZ)
1>hw10.obj : error LNK2019: unresolved external symbol __imp__fftw_plan_dft_1d referenced in function "bool __cdecl test(void)" (?test##YA_NXZ)
1>hw10.obj : error LNK2019: unresolved external symbol __imp__fftw_malloc referenced in function "bool __cdecl test(void)" (?test##YA_NXZ)
So, what could be wrong with my project setup? Thanks!
My case
Using FFTW in Visual Studio 2010
Precompiled FFTW 3.3.1 Windows DLLs install using fftw-3.2.1-dll.zip, on my Windows XP machine.
Open cmd window and go to lib.exe folder C:\Program Files\Microsoft Visual Studio 10.0\VC\bin>
Type lib /def:libfftw3-3.def
Type lib /def:libfftw3f-3.def
Type lib /def:libfftw3l-3.def
If you have a error on command, copy any mspdb80.dll or mspdb100.dll file to in bin directory.
You will get 6 files
libfftw3-3.exp, libfftw3-3.lib, libfftw3f-3.exp, libfftw3f-3.lib,
libfftw3l-3.exp and libfftw3l-3.lib
and copy it to programming directory.
Delete all mspdb80.dll or mspdb100.dll file from bin directory.
Closed Project and open again and rebuild it again.
Have you actually linked against the library in the project you're building?
Project -> Properties -> Linker -> Input -> Additional dependencies
You need to add the library's filename to that field.
Assuming you've actually linked your project against the lib and it doesn't work, use /verbose:lib and paste the output of that and the output of
dumpbin /exports fftw.lib | findstr fftw_free
I had similar problem. What helped was compiling the fftw libs with this help Compiling FFTW source in Visual studio. Actually more closely the problem was compiling my application Win 32 and trying to use x64 -libraries. So make sure the platform is same.