0

I want to use SFML and Google test for my project. I tried to set both up in DLL mode. I was able to start the program with SFML and it works, also google test works, at least until I try to test a class from my actual project.

I use VS2013 and have structured my project(s) like that.

Project structure

If I try to use a class from the "Pacman" project it fails with the following:

1>------ Rebuild All started: Project: Pacman, Configuration: Release Win32 ------
1>  Main.cpp
1>  TestMe.cpp
1>  Generating Code...
1>  .NETFramework,Version=v4.0.AssemblyAttributes.cpp
1>  LINK : /LTCG specified but no code generation required; remove /LTCG from the link command line to improve linker performance
1>  Pacman.vcxproj -> C:\Users\xxxx\Documents\Git\pacman\Pacman\Release\Pacman.exe
2>------ Rebuild All started: Project: Pacman_Test, Configuration: Release Win32 ------
2>  Pacman_Test.cpp
2>Pacman_Test.obj : error LNK2001: unresolved external symbol "public: int __thiscall TestMe::TestMyValue(int)" (?TestMyValue@TestMe@@QAEHH@Z)
2>Pacman_Test.obj : error LNK2001: unresolved external symbol "public: __thiscall TestMe::TestMe(void)" (??0TestMe@@QAE@XZ)
2>C:\Users\xxx\Documents\Git\pacman\Pacman\Release\Pacman_Test.exe : fatal error LNK1120: 2 unresolved externals
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========

Can anyone help?

EDIT how should it help to mark it as a duplicate? I can't see where there would be duplicate declarations in my project.

EDIT2 Here is the code for the TestMe class and yes it works in the main.cpp.

#pragma once
class TestMe
{
public:
    TestMe();
    int TestMyValue(int val);
};


#include "TestMe.h"

TestMe::TestMe(){}

int TestMe::TestMyValue(int val){ 
    return 0; 
}

To complete the code here is the main.cpp too:

#include <iostream>
#include <SFML/Graphics.hpp>
#include "TestMe.h"

int main()
{
    TestMe testMe;
    std::cout << "Value:"  << testMe.TestMyValue(3) << std::endl ;

    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }
    return 0;
}
simonides
  • 3,040
  • 3
  • 19
  • 34
  • Have you tested to make sure that the TestMe class alone is working? Post your code for that class. Or if it is really long than do an isolated test on it by removing everything that that has to do with Google test and SFML & see if the objects method(s) return the values that you were expecting. – Donald Oct 03 '15 at 00:08
  • @Donald Please see my edits. – simonides Oct 03 '15 at 07:43
  • Yeah, that code works fine. If you said Google Test, SFML, & your class all work in isolated tests then you can just start removing stuff in your code until the exception goes away. If in the end, you literally have only main function and return 1, then try in a whole new solution, or reinstall your visual studio. – Donald Oct 03 '15 at 17:38
  • Well I've tried to do it in a fresh install of VS2013 and VS2015, and it is basically only a main that returns 0; I have tried to do it without SFML too but the problem seems to be that I can't use classes of the other project. – simonides Oct 04 '15 at 11:24

0 Answers0