Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Need help with ResourceHolder class from book  (Read 2331 times)

0 Members and 1 Guest are viewing this topic.

sakib

  • Newbie
  • *
  • Posts: 2
    • View Profile
Need help with ResourceHolder class from book
« on: December 22, 2013, 10:01:36 pm »
I am going through the SFML game development book and I hit a road block with the resource holder class. I am developing on mac using xCode.

I implemented the class based on the book and I am trying to use it but I get this error

Undefined symbols for architecture x86_64:
  "ResourceHolder<sf::Texture, Textures::ID>::load(Textures::ID, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


for the following usage

ResourceHolder<sf::Texture, Textures::ID> textures;
   try
   {
        std::string loc = resourcePath()+"Eagle.png";
        textures.load(Textures::Airplane, loc);
         }
   catch (std::runtime_error& e)
   {
      std::cout << "Exception: " << e.what() << std::endl;
      return 1;
   }

I dont understand why this is happening.
I attached the source files if that helps

Thanks

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Need help with ResourceHolder class from book
« Reply #1 on: December 22, 2013, 10:06:29 pm »
Looks like a linker error. Did you follow the tutorial in the ReadMe.txt file? Is the implementation file ResourceHolder.inl included?

Make also sure you use the latest code from GitHub, the one from the PacktPub homepage is outdated.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

sakib

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Need help with ResourceHolder class from book
« Reply #2 on: December 22, 2013, 10:18:27 pm »
interesting... I implemented the resource holder class in a file called ResourceHolder.cpp. Why is that turning out to be a problem?

Also I never used a .inl file before, what is that supposed to be? I am really confused why we use inl file and not .cpp file

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Need help with ResourceHolder class from book
« Reply #3 on: December 22, 2013, 10:29:31 pm »
Templates must always be defined in the header, so that the compiler knows the full definition to substitute the template parameters. In order to keep interface and implementation separate, both are split into .hpp and .inl files, where the latter is included at the end of the former.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything