Visual Studio 2010 LibTomCrypt Build or Library Linking Error - c++

Using the the entire LibTomCrypt source, I've built a library file with Visual Studio 2010 which compiles without issue. However, when creating a simple test console application that links the with TomCrypt library, I receive a linker error for the following code:
Test Code:
#include <stdio.h>
#include <tomcrypt.h>
int main()
{
int Cipher;
register_cipher( &aes_desc );
Cipher = find_cipher( "aes" );
if( Cipher != CRYPT_OK )
return 0;
printf( "Cipher name: %s\n", cipher_descriptor[ Cipher ].name );
unregister_cipher( &aes_desc );
return 0;
}
Linker Error:
error LNK1120: 1 unresolved externals
error LNK2001: unresolved external symbol _aes_desc
Interestingly, the debug library build works perfectly with the test code. It is the release build of tomcrypt.lib that seems to be missing some symbols.
Now I'm not new to building and using library files, but I'm wondering, are there some specific compiler flags or precautions I can make to build the library in release mode and have it link correctly in my test program? Could it be that the static aes_desc structure, defined in the LibTomCrypt code, be missing from the release build of the library by way of some compiler optimization?
I hope someone can offer some insight for myself and anyone else experiencing this issue.

I just ran into a related issue today. The project configs for visual studio include custom steps for building aes.c, but only cover Debug builds. Once I made comparable provisions for Release builds, all was well.
Open the Visual Studio 2010 project in text editor and replace the custom build steps with the ones below. This will also fix some warnings for the Debug build:
<CustomBuild Include="src\ciphers\aes\aes.c">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">cl /nologo /MTd /W3 /Gm /EHsc /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Debug/libtomcrypt.pch" /Fo"Debug/" /Fd"Debug/" /FD /RTC1 /c %(FullPath)
cl /nologo /DENCRYPT_ONLY /MTd /W3 /Gm /EHsc /ZI /Od /I "src\headers" /I "..\libtommath" /D "_DEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Debug/libtomcrypt.pch" /Fo"Debug/aes_enc.obj" /Fd"Debug/" /FD /RTC1 /c %(FullPath)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug/aes.obj;Debug/aes_enc.obj;%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="src\ciphers\aes\aes.c">
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">cl /nologo /MT /W3 /O2 /I "src\headers" /I "..\libtommath" /D "NDEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Release/libtomcrypt.pch" /Fo"Release/" /Fd"Release/" /FD /c %(FullPath)
cl /nologo /DENCRYPT_ONLY /MT /W3 /O2 /I "src\headers" /I "..\libtommath" /D "NDEBUG" /D "LTM_DESC" /D "WIN32" /D "_MBCS" /D "_LIB" /D "LTC_SOURCE" /D "USE_LTM" /Fp"Release/libtomcrypt.pch" /Fo"Release/aes_enc.obj" /Fd"Release/" /FD /c %(FullPath)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release/aes.obj;Release/aes_enc.obj;%(Outputs)</Outputs>
</CustomBuild>

Related

Visual Studio: two little projects with identical "Command Lines" but one cannot find the headers?

I have a solution with two one-source-file projects in it. Each file is:
#include <mosquitto.h>
The first compiles fine. The second says it cannot find a header. The source code in the second is identical to the first, so it is a mystery why it cannot compile.
Pre-compiled headers are not being used in either, so it is curious that the /Fp option is issued, I don't see how it can be playing a role.
/permissive- /ifcOutput "x64\Release\" /GS /GL /W3 /Gy /Zc:wchar_t /I"C:\Program Files\mosquitto2.0.14\devel" /Zi /Gm- /Od /sdl /Fd"x64\Release\vc143.pdb" /Zc:inline /fp:precise /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /FC /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /Fp"x64\Release\Good.pch" /diagnostics:column
/permissive- /ifcOutput "x64\Release\" /GS /GL /W3 /Gy /Zc:wchar_t /I"C:\Program Files\mosquitto2.0.14\devel" /Zi /Gm- /O2 /sdl /Fd"x64\Release\vc143.pdb" /Zc:inline /fp:precise /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /FC /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /Fp"x64\Release\Bad.pch" /diagnostics:column
Another user suggests posting the actual failed output.
Build started...
1>------ Build started: Project: Bad, Configuration: Debug x64 ------
1>Bad.cpp
1>T:\MyFirm\dev\MinorProjects\Bad\Bad.cpp(55,10): fatal error C1083: Cannot open include file: 'mosquitto.h': No such file or directory
1>Done building project "Bad.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I turned on Tools->Options->Projects and Solutions->Build and Run->verbosity=Detailed, and compared the CL.exe commands issued.
To my surprise, the /I include option was NOT present on the failed build command, despite being in the Properties dialog "Command Line" page as pasted above.
The issue was that I was building in Debug, but for some reason the Properties dialog was editing Release options. So, while the "Command Line" page was showing the options that would be used were I building Release, they weren't used while building Debug.

Build an x64 DLL with Visual Studio

I'm trying to build my dll file as x64, here are the configurations I have done on VisualStudio:
I have set solution and project platform to x64:
According to this answer, I have changed naming convention from __cdecl to __fastcall:
According to this comment I have added the argument _WIN64 to Preprocessor Definitions:
But still, when I rebuild my project and open my dll file using notepad, I see PE L which means my dll file is 32 bit.
Here's the command line options of the C/C++ settings (for better reading, I put a couple of line breaks in there):
/JMC /permissive- /GS /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl
/Fd"x64\Debug\vc142.pdb" /Zc:inline /fp:precise /D "_WIN64" /D "_DEBUG" /D
"_CONSOLE" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX-
/Zc:forScope /RTC1 /Gr /MDd /FC /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\"
/Fp"x64\Debug\DllCall-CppConsoleApp-1.pch" /diagnostics:column
Linker settings:
What should I do?

TeamCity building C++ with Visual Studio Solution

I have a small test project that I want to build with TeamCity. In TeamCity I have created a build step with runner type 'Visual Studio' solution. The problem is it is not building. The error I get is:
error C1069: cannot read compiler command line
Here a part of the build log:
[16:55:05]ClCompile
[16:55:05]CL
[16:55:05]C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:queue UnitTest.cpp
[16:55:05]UnitTest.cpp
[16:55:05]c:\data\teamcity buildagent\work\d8c46b39964cb4dc\testlibrary\unittest.cpp(27, 0): error C1069: cannot read compiler command line
Try removing the space in the TeamCity build agent path:
c:\data**teamcity buildagent**\work\d8c46b39964cb4dc\testlibrary\unittest.cpp
There is a bug with the VS2013 compiler as documented here:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/82304c15-37e2-4761-8928-0c67e074bf47/error-c1069-cannot-read-compiler-command-line-on-visual-studio-2013-rc?forum=vcgeneral
(Note, this is referring to the RC and could now be fixed)

MSBuild.exe doesn't respect /MT compiler flag?

I was surprised to see that after switching our build system from VS2008 to VS2010 our application now complains that MSVCR100.dll is missing at runtime. I checked our project's build options and we are specifying Multi-threaded (/MT) for the Runtime Library. However, when we build using the GUI, the DLL is statically linked and the error does not appear. The error only happens when we build using MSBuild.exe from the command line.
I compared the command lines, and they are almost the same, both specify /MT:
VS2010 GUI:
/nologo /W3 /WX- /O2 /Oi /Oy- /GL /D "_CRT_SECURE_NO_WARNINGS" /D "GSL_DLL" /D "WIN32" /D >"_WINDOWS" /D "_USRDLL" /D "_VC80_UPGRADE=0x0710" /D "__STDC_CONSTANT_MACROS" /D >"_WINDLL" /D "_UNICODE" /D "UNICODE" /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t >/Zc:forScope /Fp"Release\Temp\ourProject.pch" /Fa"Release\Temp\" /Fo"Release\Temp\" >/Fd"Release\Temp\vc100.pdb" /Gd /analyze- /errorReport:queue
MSBuild.exe:
MSBuild.exe "%WORKSPACE%\OurProject.vcxproj" /t:Rebuild /p:Configuration=Release
/nologo /W3 /WX- /O2 /Oi /Oy- /GL /D _CRT_SECURE_NO_WARNINGS /D GSL_DLL /D WIN32 /D _WINDOWS /D _USRDLL /D _VC80_UPGRADE=0x0710 /D __STDC_CONSTANT_MACROS /D _WINDLL /D _UNICODE /D UNICODE /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope > /Fo"Release\Temp\" /Fd"Release\Temp\vc100.pdb" /Gd /TP /analyze- /errorReport:queue
I have seen some posts about VS2010 static linking not behaving as expected, however my project builds and links just fine. It is not until runtime that it cannot find the required DLL. Installing the VS2010 runtime or shipping with the runtime are options we are trying to avoid.
Thanks!

Error c2061 when compiling

When I compile a project I get this error:
C:\DATOSA~1\FAXENG~1>nmake /f
Makefile.vc clean
Microsoft (R) Program Maintenance
Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation.
All rights reserved.
cd src
nmake /nologo /f Makefile.vc clean
del /F *.obj *.lib *.dll *.exe *.res *.exp
cd..
cd tools
nmake /nologo /f Makefile.vc clean
del *.obj *.lib *.dll *.exe
No se encuentra C:\DATOSA~1\FAXENG~1\tools\*.obj
cd ..
C:\DATOSA~1\FAXENG~1>nmake /f
Makefile.vc
Microsoft (R) Program Maintenance
Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation.
All rights reserved.
cd src
nmake /nologo /f Makefile.vc
cl /nologo /MT /W3 /EHsc /O2 /I "..\..\tiff-3.8.2\libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassOne.cpp ClassOne.cpp
cl /nologo /MT /W3 /EHsc /O2 /I "..\..\tiff-3.8.2\libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassOnePointZero. ClassOnePointZero.cpp
cl /nologo /MT /W3 /EHsc /O2 /I "..\..\tiff-3.8.2\libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassTwo.cpp ClassTwo.cpp
cl /nologo /MT /W3 /EHsc /O2 /I "..\..\tiff-3.8.2\libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassTwoPointOne.c ClassTwoPointOne.cpp
cl /nologo /MT /W3 /EHsc /O2 /I "..\..\tiff-3.8.2\libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassTwoPointZero. ClassTwoPointZero.cpp
cl /nologo /MT /W3 /EHsc /O2 /I "..\..\tiff-3.8.2\libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ClassZero.cpp ClassZero.cpp
cl /nologo /MT /W3 /EHsc /O2 /I "..\..\tiff-3.8.2\libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c CommPort.cpp CommPort.cpp
cl /nologo /MT /W3 /EHsc /O2 /I "..\..\tiff-3.8.2\libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c ECMBuffer.cpp ECMBuffer.cpp
cl /nologo /MT /W3 /EHsc /O2 /I "..\..\tiff-3.8.2\libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c excepthandler.cpp excepthandler.cpp
cl /nologo /MT /W3 /EHsc /O2 /I "..\..\tiff-3.8.2\libtiff" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /c FaxAPI.cpp FaxAPI.cpp
FaxAPI.cpp(143) : error C2061: syntax error : identifier 'CClassZero'
NMAKE : fatal error U1077: '"c:\Archivos de programa\Microsoft Visual Studio 9.0\VC\BIN\cl.EXE"' : return code '0x2' Stop.
NMAKE : fatal error U1077: '"c:\Archivos de programa\Microsoft Visual Studio 9.0\VC\BIN\nmake.EXE"' : return code '0x2' Stop.
The only thing I did was copy and paste ClassTwoPointOne files into ClassZero files and change names...
ClassTwoPointOne.h:
#ifndef CLASSTWOPOINTONE_H
#define CLASSTWOPOINTONE_H
#include "ClassTwoPointZero.h"
class CClassTwoPointOne : public CClassTwoPointZero
{
public:
CClassTwoPointOne();
virtual ~CClassTwoPointOne();
virtual void SetFClass(void);
};
#endif // CLASSTWOPOINTONE_H
ClassTwoPointOne.cpp:
#include "stdafx.h"
#include "ClassTwoPointOne.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CClassTwoPointOne::CClassTwoPointOne()
{
m_sEIAClass = "2.1";
m_nScanTime = 0;
}
CClassTwoPointOne::~CClassTwoPointOne()
{
}
void CClassTwoPointOne::SetFClass(void)
{
SendCommand( COMMAND_SET_FCLASS_2_1);
}
ClassZero.h:
#ifndef CLASSZERO_H
#define CLASSZERO_H
#include "VoiceModem.h"
class CClassZero : public CVoiceModem
{
public:
CClassZero();
virtual ~CClassZero();
};
#endif // CLASSZERO_H
ClassZero.cpp:
#include "stdafx.h"
#include "ClassZero.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CClassZero::CClassZero()
{
}
CClassZero::~CClassZero()
{
}
I don't understand whats wrong... anyone can help?
Thanks a lot
FaxAPI.cpp(143) : error C2061: syntax
error : identifier 'CClassZero'
The error is at or near line number 143, in file FaxAPI.cpp.
The error is related to the identifier CClassZero
(Possibly being undefined, or misused. Possibly something as mundane as a missing semicolon).
If you cannot find the error in FaxAPI.cpp yourself, you need to provide us with the relevant part of that file.
msdn says c2061: "The compiler found an identifier where it wasn't expected. Make sure that identifier is declared before you use it." So apparently class CClassZero became undeclared after you messed with the files, makesure that you include appropriate files and that they contain a valid declaration of class CClassZero