Page 1 of 1

Linking problem when using files from other project

Posted: Thu Feb 12, 2015 12:55 am
by spert
Hi,

First, Thanks to Eran and everybody else working on this IDE. It is really nice you put so much effort into it and also support multiple operating systems!

System Information:

Code: Select all


OS:      : Windows 7, 64 Bit
CodeLite : version 7.0 , 64 Bit 
                - codelite-amd64-7.0.exe from the homepage) 
                - installed to folder C:\Program Files\CodeLite
Compiler : Mingw 4.8.1
                - installed to folder C:\MinGW-4.8.1
General Information:
I made a workspace proc_space ( located at C:\cpp_projects\proc_space ) which contains two projects:
  • game
  • game_test
folder-structure inside proc_space folder:

Code: Select all

 proc_space                 
├───game                 
│       Bomb.hpp         
│       Bullet.hpp       
│       Constants.hpp    
│       Entity.hpp       
│       Game.cpp         
│       Game.hpp         
│       game.mk          
│       game.project     
│       game.txt         
│       main.cpp         
│       main.hpp         
│       qt.hpp           
│       QuadTree.cpp     
│       QuadTree.hpp     
│       Ship.hpp         
│       SpatialHash.cpp  
│       SpatialHash.hpp  
│                        
└───game_test            
        game_test.mk     
        game_test.project
        game_test.txt    
        main.cpp         
game project setup:
I use the standard template library and SFML 2.2 ( located at C:\dev_libs_cpp\SFML-2.2 )

game.project (build configuration):

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Project Name="game" InternalType="Console">
  <Plugins>
    <Plugin Name="qmake">
      <![CDATA[00020001N0005Debug0000000000000001N0007Release000000000000]]>
    </Plugin>
    <Plugin Name="CMakePlugin">
      <![CDATA[[{
  "name": "Debug",
  "enabled": false,
  "buildDirectory": "build",
  "sourceDirectory": "$(ProjectPath)",
  "generator": "",
  "buildType": "",
  "arguments": [],
  "parentProject": ""
 }, {
  "name": "Release",
  "enabled": false,
  "buildDirectory": "build",
  "sourceDirectory": "$(ProjectPath)",
  "generator": "",
  "buildType": "",
  "arguments": [],
  "parentProject": ""
 }]]]>
    </Plugin>
  </Plugins>
  <Description/>
  <Dependencies/>
  <VirtualDirectory Name="src">
    <File Name="main.cpp"/>
    <File Name="Entity.hpp"/>
    <File Name="main.hpp"/>
    <File Name="Ship.hpp"/>
    <File Name="Game.hpp"/>
    <File Name="Game.cpp"/>
    <File Name="Bullet.hpp"/>
    <File Name="Constants.hpp"/>
    <File Name="Bomb.hpp"/>
    <File Name="SpatialHash.hpp"/>
    <File Name="SpatialHash.cpp"/>
    <File Name="QuadTree.hpp"/>
    <File Name="QuadTree.cpp"/>
  </VirtualDirectory>
  <Settings Type="Executable">
    <GlobalSettings>
      <Compiler Options="" C_Options="" Assembler="">
        <IncludePath Value="."/>
      </Compiler>
      <Linker Options="">
        <LibraryPath Value="."/>
      </Linker>
      <ResourceCompiler Options=""/>
    </GlobalSettings>
    <Configuration Name="Debug" CompilerType="MinGW ( CodeLite-4.8.1 )" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
      <Compiler Options="-g;-O0;-std=c++11;-Wall" C_Options="-g;-O0;-Wall" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
        <IncludePath Value="."/>
        <IncludePath Value="C:/dev_libs_cpp/SFML-2.2/include"/>
      </Compiler>
      <Linker Options="" Required="yes">
        <LibraryPath Value="C:/dev_libs_cpp/SFML-2.2/lib"/>
        <Library Value="sfml-main-d"/>
        <Library Value="sfml-system-d"/>
        <Library Value="sfml-graphics-d"/>
        <Library Value="sfml-window-d"/>
        <Library Value="sfml-audio-d"/>
      </Linker>
      <ResourceCompiler Options="" Required="no"/>
      <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
      <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>">
        <![CDATA[]]>
      </Environment>
      <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
        <DebuggerSearchPaths/>
        <PostConnectCommands/>
        <StartupCommands/>
      </Debugger>
      <PreBuild/>
      <PostBuild/>
      <CustomBuild Enabled="no">
        <RebuildCommand/>
        <CleanCommand/>
        <BuildCommand/>
        <PreprocessFileCommand/>
        <SingleFileCommand/>
        <MakefileGenerationCommand/>
        <ThirdPartyToolName>None</ThirdPartyToolName>
        <WorkingDirectory/>
      </CustomBuild>
      <AdditionalRules>
        <CustomPostBuild/>
        <CustomPreBuild/>
      </AdditionalRules>
      <Completion EnableCpp11="no">
        <ClangCmpFlagsC/>
        <ClangCmpFlags/>
        <ClangPP/>
        <SearchPaths/>
      </Completion>
    </Configuration>
    <Configuration Name="Release" CompilerType="MinGW ( CodeLite-4.8.1 )" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
      <Compiler Options="-O2;-std=c++11;-Wall" C_Options="-O2;-Wall" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
        <IncludePath Value="."/>
        <IncludePath Value="C:/dev_libs_cpp/SFML-2.2/include"/>
        <Preprocessor Value="NDEBUG"/>
      </Compiler>
      <Linker Options="" Required="yes">
        <LibraryPath Value="C:/dev_libs_cpp/SFML-2.2/lib"/>
        <Library Value="sfml-main-d"/>
        <Library Value="sfml-system-d"/>
        <Library Value="sfml-graphics-d"/>
        <Library Value="sfml-window-d"/>
        <Library Value="sfml-audio-d"/>
      </Linker>
      <ResourceCompiler Options="" Required="no"/>
      <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Release" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
      <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>">
        <![CDATA[]]>
      </Environment>
      <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
        <DebuggerSearchPaths/>
        <PostConnectCommands/>
        <StartupCommands/>
      </Debugger>
      <PreBuild/>
      <PostBuild/>
      <CustomBuild Enabled="no">
        <RebuildCommand/>
        <CleanCommand/>
        <BuildCommand/>
        <PreprocessFileCommand/>
        <SingleFileCommand/>
        <MakefileGenerationCommand/>
        <ThirdPartyToolName>None</ThirdPartyToolName>
        <WorkingDirectory/>
      </CustomBuild>
      <AdditionalRules>
        <CustomPostBuild/>
        <CustomPreBuild/>
      </AdditionalRules>
      <Completion EnableCpp11="no">
        <ClangCmpFlagsC/>
        <ClangCmpFlags/>
        <ClangPP/>
        <SearchPaths/>
      </Completion>
    </Configuration>
  </Settings>
</CodeLite_Project>
game project debug build output (works ):

Code: Select all

C:\Windows\system32\cmd.exe /C "C:/MinGW-4.8.1/bin/mingw32-make.exe -j4 SHELL=cmd.exe  -e -f  Makefile"
"----------Building project:[ game - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/cpp_projects/proc_space/game'
C:/MinGW-4.8.1/bin/g++.exe   -c  "C:/cpp_projects/proc_space/game/main.cpp" -g -O0 -std=c++11 -Wall  -o ./Debug/main.cpp.o -I. -I. -IC:/dev_libs_cpp/SFML-2.2/include
C:/MinGW-4.8.1/bin/g++.exe   -c  "C:/cpp_projects/proc_space/game/Game.cpp" -g -O0 -std=c++11 -Wall  -o ./Debug/Game.cpp.o -I. -I. -IC:/dev_libs_cpp/SFML-2.2/include
C:/MinGW-4.8.1/bin/g++.exe   -c  "C:/cpp_projects/proc_space/game/SpatialHash.cpp" -g -O0 -std=c++11 -Wall  -o ./Debug/SpatialHash.cpp.o -I. -I. -IC:/dev_libs_cpp/SFML-2.2/include
C:/MinGW-4.8.1/bin/g++.exe   -c  "C:/cpp_projects/proc_space/game/QuadTree.cpp" -g -O0 -std=c++11 -Wall  -o ./Debug/QuadTree.cpp.o -I. -I. -IC:/dev_libs_cpp/SFML-2.2/include
C:/MinGW-4.8.1/bin/g++.exe  -o ./Debug/game @"game.txt" -L. -LC:/dev_libs_cpp/SFML-2.2/lib  -lsfml-main-d -lsfml-system-d -lsfml-graphics-d -lsfml-window-d -lsfml-audio-d
mingw32-make.exe[1]: Leaving directory 'C:/cpp_projects/proc_space/game'
0 errors, 0 warnings
In the game project the subfolder Debug is created (see contents below):

Code: Select all

    .d
    Game.cpp.o
    Game.cpp.o.d
    game.exe
    main.cpp.o
    main.cpp.o.d
    QuadTree.cpp.o
    QuadTree.cpp.o.d
    SpatialHash.cpp.o
    SpatialHash.cpp.o.d
To run the game I need to add the sfml dlls but I omit that part here.

Here the problems start :roll:


game_test project setup:
In the game_test project I want to test certain functionality of project game.
I use the Unittest++ (located at C:\UnitTest++-1.3 ) and again SFML 2.2 ( located at C:\dev_libs_cpp\SFML-2.2 )

game_test.project (build configuration):

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Project Name="game_test" InternalType="UnitTest++">
  <Plugins>
    <Plugin Name="qmake">
      <![CDATA[00010001N0005Debug000000000000]]>
    </Plugin>
    <Plugin Name="CMakePlugin">
      <![CDATA[[{
  "name": "Debug",
  "enabled": false,
  "buildDirectory": "build",
  "sourceDirectory": "$(ProjectPath)",
  "generator": "",
  "buildType": "",
  "arguments": [],
  "parentProject": ""
 }, {
  "name": "Release",
  "enabled": false,
  "buildDirectory": "build",
  "sourceDirectory": "$(ProjectPath)",
  "generator": "",
  "buildType": "",
  "arguments": [],
  "parentProject": ""
 }]]]>
    </Plugin>
  </Plugins>
  <Description/>
  <Dependencies/>
  <VirtualDirectory Name="src">
    <File Name="main.cpp"/>
  </VirtualDirectory>
  <Settings Type="Executable">
    <GlobalSettings>
      <Compiler Options="" C_Options="" Assembler="">
        <IncludePath Value="."/>
      </Compiler>
      <Linker Options="">
        <LibraryPath Value="."/>
      </Linker>
      <ResourceCompiler Options=""/>
    </GlobalSettings>
    <Configuration Name="Debug" CompilerType="MinGW ( CodeLite-4.8.1 )" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
      <Compiler Options="-g;-std=c++11" C_Options="-g" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
        <IncludePath Value="$(UNIT_TEST_PP_SRC_DIR)/src"/>
        <IncludePath Value="."/>
        <IncludePath Value="C:/UnitTest++-1.3/src"/>
        <IncludePath Value="C:/dev_libs_cpp/SFML-2.2/include"/>
        <IncludePath Value="C:/cpp_projects/proc_space/game"/>
      </Compiler>
      <Linker Options="" Required="yes">
        <LibraryPath Value="$(UNIT_TEST_PP_SRC_DIR)/Debug"/>
        <LibraryPath Value="C:/cpp_projects/proc_space/game/Release"/>
        <LibraryPath Value="C:/cpp_projects/proc_space/game/Debug"/>
        <LibraryPath Value="C:/dev_libs_cpp/SFML-2.2/lib"/>
        <Library Value="libUnitTest++.a"/>
        <Library Value="QuadTree.cpp.o"/>
      </Linker>
      <ResourceCompiler Options="" Required="no"/>
      <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
      <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>">
        <![CDATA[]]>
      </Environment>
      <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
        <DebuggerSearchPaths/>
        <PostConnectCommands/>
        <StartupCommands/>
      </Debugger>
      <PreBuild/>
      <PostBuild/>
      <CustomBuild Enabled="no">
        <RebuildCommand/>
        <CleanCommand/>
        <BuildCommand/>
        <PreprocessFileCommand/>
        <SingleFileCommand/>
        <MakefileGenerationCommand/>
        <ThirdPartyToolName>None</ThirdPartyToolName>
        <WorkingDirectory/>
      </CustomBuild>
      <AdditionalRules>
        <CustomPostBuild/>
        <CustomPreBuild/>
      </AdditionalRules>
      <Completion EnableCpp11="no">
        <ClangCmpFlagsC/>
        <ClangCmpFlags/>
        <ClangPP/>
        <SearchPaths/>
      </Completion>
    </Configuration>
    <Configuration Name="Release" CompilerType="MinGW ( CodeLite-4.8.1 )" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
      <Compiler Options="" C_Options="" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
        <IncludePath Value="."/>
        <IncludePath Value="$(UNIT_TEST_PP_SRC_DIR)/src"/>
      </Compiler>
      <Linker Options="-O2" Required="yes">
        <LibraryPath Value="$(UNIT_TEST_PP_SRC_DIR)/Release"/>
        <Library Value="libUnitTest++.a"/>
      </Linker>
      <ResourceCompiler Options="" Required="no"/>
      <General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="Release" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
      <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>">
        <![CDATA[]]>
      </Environment>
      <Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
        <DebuggerSearchPaths/>
        <PostConnectCommands/>
        <StartupCommands/>
      </Debugger>
      <PreBuild/>
      <PostBuild/>
      <CustomBuild Enabled="no">
        <RebuildCommand/>
        <CleanCommand/>
        <BuildCommand/>
        <PreprocessFileCommand/>
        <SingleFileCommand/>
        <MakefileGenerationCommand/>
        <ThirdPartyToolName>None</ThirdPartyToolName>
        <WorkingDirectory/>
      </CustomBuild>
      <AdditionalRules>
        <CustomPostBuild/>
        <CustomPreBuild/>
      </AdditionalRules>
      <Completion EnableCpp11="no">
        <ClangCmpFlagsC/>
        <ClangCmpFlags/>
        <ClangPP/>
        <SearchPaths/>
      </Completion>
    </Configuration>
  </Settings>
</CodeLite_Project>
TLDR version (only linker information:

Code: Select all

      <Linker Options="" Required="yes">
        <LibraryPath Value="$(UNIT_TEST_PP_SRC_DIR)/Debug"/>
        <LibraryPath Value="C:/cpp_projects/proc_space/game/Release"/>
        <LibraryPath Value="C:/cpp_projects/proc_space/game/Debug"/>
        <LibraryPath Value="C:/dev_libs_cpp/SFML-2.2/lib"/>
        <Library Value="libUnitTest++.a"/>
        <Library Value="QuadTree.cpp.o"/>
      </Linker>
My main.cpp looks like this:

Code: Select all

#include <UnitTest++.h>
#include "SFML\Window.hpp"
#include "QuadTree.hpp"


// run all tests
int main(int argc, char **argv)
{
	return UnitTest::RunAllTests();
}

TEST(Test_QuadTree)
{
	QuadTree qt = QuadTree(0, sf::Vector2f(0.0f, 0.0f), sf::Vector2f(512.0f, 512.0f));
}
There is no CHECK used right now but that does not matter.

When I try to compile this I get the following output:

Code: Select all

C:\Windows\system32\cmd.exe /C "C:/MinGW-4.8.1/bin/mingw32-make.exe -j4 SHELL=cmd.exe  -e -f  Makefile"
"----------Building project:[ game_test - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/cpp_projects/proc_space/game_test'
C:/MinGW-4.8.1/bin/g++.exe   -c  "C:/cpp_projects/proc_space/game_test/main.cpp" -g -std=c++11  -o Debug/main.cpp.o -I. -IC:\UnitTest++-1.3/src -I. -IC:/UnitTest++-1.3/src -IC:/dev_libs_cpp/SFML-2.2/include -IC:/cpp_projects/proc_space/game
C:/MinGW-4.8.1/bin/g++.exe  -o Debug/game_test @"game_test.txt" -L. -LC:\UnitTest++-1.3/Debug -LC:/cpp_projects/proc_space/game/Release -LC:/cpp_projects/proc_space/game/Debug -LC:/dev_libs_cpp/SFML-2.2/lib  -lUnitTest++ -lQuadTree.cpp.o
c:/mingw-4.8.1/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lQuadTree.cpp.o
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/game_test] Error 1
mingw32-make.exe: *** [All] Error 2
game_test.mk:81: recipe for target 'Debug/game_test' failed
mingw32-make.exe[1]: Leaving directory 'C:/cpp_projects/proc_space/game_test'
Makefile:4: recipe for target 'All' failed
1 errors, 0 warnings
TLDR version (only error message):

Code: Select all

cannot find -lQuadTree.cpp.o
I tried to change the Library in the configuration to QuadTree.cpp.o.d but it gave me a similar error. I also tried to compile game project in Release configuration (that's why also the Release folder is in the linker folders of game_test project) before running the game_test build.

Do I perhaps miss something?

Thanks for any help, suggestions. I hope I didn't paste too much text. :oops:

Re: Linking problem when using files from other project

Posted: Thu Feb 12, 2015 10:25 am
by eranif
I tried to change the Library in the configuration to QuadTree.cpp.o.d but it gave me a similar error
Why are you messing with the objects directly? You should not attempt to pass an object file (e.g. QuadTree.cpp.o) directly to the linker using the "-l" switch
You should remote this completely. The linker will not find it because it is not a library

Eran

Re: Linking problem when using files from other project

Posted: Fri Feb 13, 2015 12:12 am
by spert
That's a very good question. Thanks for pointing this out. That was actually a pretty stupid move. Thanks! :roll: :oops:

I was able to solve my problem by creating another project ( dll) in my workspace called game_libraries where I moved all classes like QuadTree, Entity, etc. and then link to it in my game and game_test project. So when I compile the game_libraries project and link to it's Debug-path from game and game_test it works fine.


Another question if I may?

When I added Tests directly to the main.cpp in game_test it worked fine.

Then I created a separate file using the context menu to create a specific test file (in a subdirectory "tests" for QuadTree (named test_QuadTree) which contains auto generated test cases for all methods in class QuadTree.

Compilation of game_test works.

After I click on the "run tests button" in the IDE it I get a message box saying "Project contains 0 tests. Nothing to be done." .

Do I need to add something to the main.cpp in game_test to also run the tests in test_QuadTree.cpp ?

main.cpp contains currently:

Code: Select all

#include <UnitTest++.h>

// run all tests
int main(int argc, char **argv)
{
	return UnitTest::RunAllTests();
}
Output of the game_test build:

Code: Select all

C:\Windows\system32\cmd.exe /C "C:/MinGW-4.8.1/bin/mingw32-make.exe -j4 SHELL=cmd.exe  -e -f  Makefile"
"----------Building project:[ game_test - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/cpp_projects/proc_space/game_test'
mingw32-make.exe[1]: Leaving directory 'C:/cpp_projects/proc_space/game_test'
mingw32-make.exe[1]: Entering directory 'C:/cpp_projects/proc_space/game_test'
C:/MinGW-4.8.1/bin/g++.exe   -c  "C:/cpp_projects/proc_space/game_test/test_QuadTree.cpp" -g -std=c++11  -o Debug/test_QuadTree.cpp.o -I. -IC:\UnitTest++-1.3/src -IC:\UnitTest++-1.3/test -I. -IC:/UnitTest++-1.3/src -IC:/dev_libs_cpp/SFML-2.2/include -IC:/cpp_projects/proc_space/game_libraries
C:/MinGW-4.8.1/bin/g++.exe  -o Debug/game_test @"game_test.txt" -L. -LC:\UnitTest++-1.3/Debug -LC:/cpp_projects/proc_space/game/Release -LC:/cpp_projects/proc_space/game_libraries/Debug -LC:/dev_libs_cpp/SFML-2.2/lib  -lUnitTest++ -lgame_libraries
mingw32-make.exe[1]: Leaving directory 'C:/cpp_projects/proc_space/game_test'
0 errors, 0 warnings
Thanks for any responses!

Re: Linking problem when using files from other project

Posted: Fri Feb 13, 2015 12:30 am
by spert
Garr! I'm an idiot.

I should copy the game_libraries.dll to game_test/Debug when making changes and recompiling. That solved this issue with the message box.

Sorry :oops: