1

I'm trying to compile a program with an "API" of my own. Let's say that my project's structure is:

main.cc
...
api/
    include/
        *.h
    lib/
        libsdl2ecs.a

I know that compilers (or at least gcc and clang) have options to add directories to the include and lib paths (-I and -L), so the command I'm using to compile is:

clang++ -std=c++11 -Iapi/include -Lapi/lib -Wall -o main main.cc -lSDL2 -lSDL2_image -lsdl2ecs

And it does not work: The output is too horrific to put it in here. Thing is, is not my problem, because if I remove the -Iapi/include option and write the whole paths in the .cc files it works flawlessly.

I would like to know if I am missing something.

Thanks in advance!

Edit: Error message

clang++ -std=c++11 -Iapi/include/ -Lapi/lib/ -Wall -o main main.cc -lSDL2 -lSDL2_image -lsdl2ecs
In file included from main.cc:1:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/iostream:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ostream:38:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ios:42:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/bits/ios_base.h:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ext/atomicity.h:35:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr.h:148:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr-default.h:35:
In file included from /usr/include/pthread.h:23:
In file included from /usr/include/sched.h:34:
In file included from api/include/time.h:5:
api/include/system.h:15:9: error: implicit instantiation of undefined template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
        string failureDetail;
               ^
/usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/bits/stringfwd.h:71:11: note: template is declared here
    class basic_string;
          ^
In file included from main.cc:1:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/iostream:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ostream:38:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ios:42:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/bits/ios_base.h:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ext/atomicity.h:35:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr.h:148:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr-default.h:35:
In file included from /usr/include/pthread.h:23:
In file included from /usr/include/sched.h:34:
In file included from api/include/time.h:6:
In file included from api/include/game.h:6:
In file included from api/include/entity.h:4:
api/include/component.h:24:9: error: implicit instantiation of undefined template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
        string failureDetail;
               ^
/usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/bits/stringfwd.h:71:11: note: template is declared here
    class basic_string;
          ^
In file included from main.cc:1:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/iostream:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ostream:38:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ios:42:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/bits/ios_base.h:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ext/atomicity.h:35:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr.h:148:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr-default.h:35:
In file included from /usr/include/pthread.h:23:
In file included from /usr/include/sched.h:34:
In file included from api/include/time.h:6:
In file included from api/include/game.h:6:
In file included from api/include/entity.h:4:
api/include/component.h:70:6: error: member access into incomplete type 'Game'
        game->Instantiate<T>();
            ^
api/include/system.h:4:7: note: forward declaration of 'Game'
class Game;
      ^
In file included from main.cc:1:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/iostream:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ostream:38:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ios:42:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/bits/ios_base.h:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ext/atomicity.h:35:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr.h:148:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr-default.h:35:
In file included from /usr/include/pthread.h:23:
In file included from /usr/include/sched.h:34:
In file included from api/include/time.h:6:
In file included from api/include/game.h:6:
In file included from api/include/entity.h:4:
api/include/component.h:77:15: error: member access into incomplete type 'Entity'
        return entity->AddComponent<T>();
                     ^
api/include/component.h:13:7: note: forward declaration of 'Entity'
class Entity;
      ^
api/include/component.h:84:15: error: member access into incomplete type 'Entity'
        return entity->GetComponent<Derived>();
                     ^
api/include/component.h:13:7: note: forward declaration of 'Entity'
class Entity;
      ^
In file included from main.cc:1:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/iostream:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ostream:38:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ios:42:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/bits/ios_base.h:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ext/atomicity.h:35:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr.h:148:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr-default.h:35:
In file included from /usr/include/pthread.h:23:
In file included from /usr/include/sched.h:34:
In file included from api/include/time.h:6:
In file included from api/include/game.h:6:
In file included from api/include/entity.h:6:
In file included from api/include/texture.h:8:
In file included from api/include/renderer.h:6:
api/include/display.h:14:9: error: implicit instantiation of undefined template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
        string title;
               ^
/usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/bits/stringfwd.h:71:11: note: template is declared here
    class basic_string;
          ^
In file included from main.cc:1:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/iostream:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ostream:38:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ios:42:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/bits/ios_base.h:39:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/ext/atomicity.h:35:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr.h:148:
In file included from /usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/x86_64-redhat-linux/bits/gthr-default.h:35:
In file included from /usr/include/pthread.h:23:
In file included from /usr/include/sched.h:34:
In file included from api/include/time.h:6:
In file included from api/include/game.h:6:
In file included from api/include/entity.h:6:
api/include/texture.h:18:9: error: implicit instantiation of undefined template 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
        string path;
               ^
/usr/bin/../lib/gcc/x86_64-redhat-linux/5.1.1/../../../../include/c++/5.1.1/bits/stringfwd.h:71:11: note: template is declared here
    class basic_string;
          ^
In file included from main.cc:4:
In file included from ./prefabs.hh:2:
./ccomponents.hh:20:36: error: cannot initialize object parameter of type 'Component' with an expression of type 'WASDController'
            Transform &transform = GetTransform();
                                   ^~~~~~~~~~~~
./ccomponents.hh:22:17: error: cannot initialize object parameter of type 'Component' with an expression of type 'WASDController'
            if (GetKeyPressed(SDLK_d))
                ^~~~~~~~~~~~~
./ccomponents.hh:25:17: error: cannot initialize object parameter of type 'Component' with an expression of type 'WASDController'
            if (GetKeyPressed(SDLK_w))
                ^~~~~~~~~~~~~
./ccomponents.hh:28:17: error: cannot initialize object parameter of type 'Component' with an expression of type 'WASDController'
            if (GetKeyPressed(SDLK_a))
                ^~~~~~~~~~~~~
./ccomponents.hh:31:17: error: cannot initialize object parameter of type 'Component' with an expression of type 'WASDController'
            if (GetKeyPressed(SDLK_s))
                ^~~~~~~~~~~~~
./ccomponents.hh:34:17: error: cannot initialize object parameter of type 'Component' with an expression of type 'WASDController'
            if (GetKeyDown(SDLK_v))
                ^~~~~~~~~~
./ccomponents.hh:44:36: error: cannot initialize object parameter of type 'Component' with an expression of type 'Zoomer'
            Transform &transform = GetTransform();
                                   ^~~~~~~~~~~~
./ccomponents.hh:46:17: error: cannot initialize object parameter of type 'Component' with an expression of type 'Zoomer'
            if (GetKeyPressed(SDLK_x)) {
                ^~~~~~~~~~~~~
./ccomponents.hh:51:17: error: cannot initialize object parameter of type 'Component' with an expression of type 'Zoomer'
            if (GetKeyPressed(SDLK_z)) {
                ^~~~~~~~~~~~~
./ccomponents.hh:63:36: error: cannot initialize object parameter of type 'Component' with an expression of type 'Rotator'
            Transform &transform = GetTransform();
                                   ^~~~~~~~~~~~
./ccomponents.hh:65:17: error: cannot initialize object parameter of type 'Component' with an expression of type 'Rotator'
            if (GetKeyPressed(SDLK_e))
                ^~~~~~~~~~~~~
./ccomponents.hh:68:17: error: cannot initialize object parameter of type 'Component' with an expression of type 'Rotator'
            if (GetKeyPressed(SDLK_q))
                ^~~~~~~~~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
Makefile:11: recipe for target 'main' failed
make: *** [main] Error 1
Rodolfo
  • 335
  • 1
  • 4
  • 10
  • Between `-Wall` and `main` should probably be an `-o`, I guess? Though to help with the rest you really should or that error messages to your post. – Daniel Jour Jul 06 '15 at 14:57
  • You're right @DanielJour, edited and added the error message. – Rodolfo Jul 06 '15 at 15:02
  • 1
    For starters, fix that "api of your own" by ensuring there is not responsibility on the includer to preface including your header with something else. By the looks of it, your header uses `std::string` in some fashion (worse, without namespace qualification) yet apparently didn't bother to `#include ` in your header. Don't do that. And refrain from plunking `using namespace ....;` in your headers. [Read here for why](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). – WhozCraig Jul 06 '15 at 15:13
  • As I said, it compiles well without the -I option, and I included . Anyways it does not seem to work with (it should not be the problem after all, I get none of the errors if I compile them with the full path, or if they are all in the same path). I'll consider the `using namespace std` bad practice. – Rodolfo Jul 06 '15 at 15:27
  • I am hoping your headers do not have inline function definitions, because if they do, it defeats the purpose of including both -L and -I options together – V Shreyas Jul 06 '15 at 18:14
  • @V Shreyas I actually have a couple of definitions in one or two header files, but it is because they are templates. – Rodolfo Jul 06 '15 at 18:20

0 Answers0