I'm not sure where this post belongs, but this seems like the right place.
background:
I'm an experienced programmer but new to code::blocks
Problem:
GoogleTest ( gtest-1.3.0.zip ) does not compile under code blocks but does under msvc.
I imported the project from the provided msvc sln file.
It did not correctly import the include directories for the project(s).
I set them manually.
When I try to compile I get:
-------------- Build: Debug Win32 in gtest_unittest ---------------
cl : Command line warning D9035 : option 'Wp64' has been deprecated and will be removed in a future release
cl : Command line warning D9002 : ignoring unknown option '/MLd'
gtest_unittest.cc
c:\program files\microsoft visual studio 9.0\vc\include\xlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
c:\temp\gtest-1.3.0\test\gtest_unittest.cc(913) : error C2065: '__LINE__Var' : undeclared identifier
c:\temp\gtest-1.3.0\test\gtest_unittest.cc(925) : error C2065: '__LINE__Var' : undeclared identifier
Searching for '__LINE__Var' yields no matches.
This is the first failure line:
EXPECT_FATAL_FAILURE(ASSERT_TRUE(false), "");
If you find the definition of EXPECT_FATAL_FAILURE and substitute in the parameters it compiles fine:
do {
class GTestExpectFatalFailureHelper {
public:
static void Execute() { ASSERT_TRUE(false); }
};
::testing::TestPartResultArray gtest_failures;
::testing::internal::SingleFailureChecker gtest_checker(
>est_failures, ::testing::TPRT_FATAL_FAILURE, (""));
{
::testing::ScopedFakeTestPartResultReporter gtest_reporter(
::testing::ScopedFakeTestPartResultReporter::
INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);
GTestExpectFatalFailureHelper::Execute();
}
} while (false);
Any suggestions?
>You cannot expect this to work without any modifications.
This would seem to be an issue with the compiler preprocessor. When I manually do the text substitution it compiles. Any suggestion what IDE setting is missing/wrong?
The project files were unmodified and as provided by the googletest project.
Here's one.
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="gtest_unittest"
ProjectGUID="{4D9FDFB5-986A-4139-823C-F4EE0ED481A1}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/gtest_unittest.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/gtest_unittest.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/gtest_unittest.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
<ProjectReference
ReferencedProjectIdentifier="{3AF54C8A-10BF-4332-9147-F68ED9862032}"
Name="gtest_main"/>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath="..\test\gtest_unittest.cc">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="1"
AdditionalIncludeDirectories=""..";"..\include""
BasicRuntimeChecks="0"
UsePrecompiledHeader="0"
DebugInformationFormat="3"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""..";"..\include""
UsePrecompiledHeader="0"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
> I don't exactly get what you mean by that. What pre-processor? What do you substitute to make it work?
the goolgetest project uses #defined code as 'macros' for including test conditions.
Like this:
#define EXPECT_FATAL_FAILURE(statement, substr) \
do { \
class GTestExpectFatalFailureHelper {\
public:\
static void Execute() { statement; }\
};\
::testing::TestPartResultArray gtest_failures;\
::testing::internal::SingleFailureChecker gtest_checker(\
>est_failures, ::testing::TPRT_FATAL_FAILURE, (substr));\
{\
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
::testing::ScopedFakeTestPartResultReporter:: \
INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\
GTestExpectFatalFailureHelper::Execute();\
}\
} while (false)
If I copy the code from within the #define and substitute in the text from the invocation parameters it compiles.
If I use the #define it fails with an error that makes no sense to me.
This does not compile:
EXPECT_FATAL_FAILURE(ASSERT_TRUE(false), "");
This (which should be what the compiler expands it to) does compile:
do {
class GTestExpectFatalFailureHelper {
public:
static void Execute() { ASSERT_TRUE(false); }
};
::testing::TestPartResultArray gtest_failures;
::testing::internal::SingleFailureChecker gtest_checker(
>est_failures, ::testing::TPRT_FATAL_FAILURE, (""));
{
::testing::ScopedFakeTestPartResultReporter gtest_reporter(
::testing::ScopedFakeTestPartResultReporter::
INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);
GTestExpectFatalFailureHelper::Execute();
}
} while (false);