Note that there are some explanatory texts on larger screens.

plurals
  1. PO"undefined reference to PrintArgv": why?
    primarykey
    data
    text
    <p>When I compile my program, I get three "undefined reference to 'PrintArgv(...)'" errors. I have searched but I cannot find the reason why I am getting these errors. Here is my code:</p> <pre><code> #include "tools.hpp" enum ARG_T {COMMAND, SWITCH, ARGUMENT}; void ReadArgs(int, char**, ofstream&amp;); void PrintArgv(char*, ARG_T, ofstream&amp;); int main(int argc, char* argv[]) { ofstream fout; try{ fout.open("P1Ford.txt", ios::out | ios::app); } catch(...) { //fatal("Could not open file P1Ford.txt"); cout &lt;&lt; "Could not open file P1Ford.txt" &lt;&lt; "\n"; return -1; } ReadArgs(argc, argv, fout); fout.close(); return 0; } /*----------------------------------------------------------------------------- This function takes the values passed in through the command line then examines each one to determine if it is the command, a switch or an argument. Then passes it to a function to print it to the file. -----------------------------------------------------------------------------*/ void ReadArgs(int argc, char* argv[], ofstream&amp; fout) { for(int c=0; c&lt;argc; ++c) { if(c == 0) PrintArgv(argv[c], COMMAND, fout); else if(strncmp(argv[c], "-", 1) == 0) PrintArgv(argv[c], SWITCH, fout); else if(strncmp(argv[c], "&gt;", 1) == 0) ; else PrintArgv(argv[c], ARGUMENT, fout); } } /*----------------------------------------------------------------------------- This function prints the argument in the correct format Command &lt;command&gt; Switch &lt;switch&gt; Argument &lt;agrument&gt; Argument &lt;argument&gt; -----------------------------------------------------------------------------*/ void PrintArgv(char* val, ARG_T type, ostream&amp; fout) { if(type == COMMAND) fout &lt;&lt; "Command " &lt;&lt; val &lt;&lt; "\n"; if(type == SWITCH) fout &lt;&lt; "\t" &lt;&lt; "Switch " &lt;&lt; val &lt;&lt; "\n"; if(type == ARGUMENT) fout &lt;&lt; "\t" &lt;&lt; "Argument " &lt;&lt; val &lt;&lt; "\n"; } </code></pre> <p>The function <code>ReadArgs</code> is where I am getting the errors. Each call to <code>PrintArgv</code> gives me the error. I am using G++ 4.6.1.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload