Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    g++ linking problem (my own .cpp files, no library)


    i'm new to linux programming, thow my programming experience under windows is quite good. I have a problem that i can't solve. Here it is, I hope someone will enlight me upon this :

    i have some cpp files and some .h files describing some classes.
    I wrote a template list, a template stack, a template Queue and a template HashTable.
    they seem to compile well, no errors. I use the following rule:
    HashTable.o : HashTable.cpp HashTable.h
    g++ -c HashTable
    then I have a flex output fom a flex file. This also compiles without errors
    flex ./flexygen.l
    g++ -o lex.yy.o ./lex.yy.c

    The problems occur when I try to link the files (.o) togeder.
    I need a HashTable in my flex program and I use the necessary #include directives in the flexygen.l file for including the header files (HashTable.h), but when linking:
    project : lex.yy.o HashTable.o
    g++ -o project lex.yy.o HashTable.o
    I get an error : undefined reference to HashTable< template type...>::addElement(...some type...).

    does anyone have any idea?

  2. #2
    Linux User
    Join Date
    Aug 2005

    Object reordereing

    Here is my two cents: try to specify first your HastTable object in this manner:

    g++ -o project HashTable.o lex.yy.o
    Often this solve my similar problems.
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts