1

I have a multi-file project in VSC++2010, but for some reason it won't link some of them properly.

For example, I have CParser.h and CParser.cpp . CParser.h is just some function declarations:

#pragma once
#include <string>

void parseArg(int argc, char* argv[], GVar gv);
void parseCfg(string cfg, GVar gv)

CParser.cpp just contains implementations:

#include <cstdio>
#include <fstream>
#include <cstring>
#include <string>
#include "_GlobalVar.h" //defines GVar, not relevant
#include "CParser.h"

void parseArg(int argc, char* argv[], GVar &gv) {
    /*not really relevant*/
}

And the error:

main.obj : error LNK2019: unresolved external symbol "void __cdecl parseArg(int,char * * const,class GVar)" (?parseArg@@YAXHQAPADVGVar@@@Z) referenced in function _SDL_main

Edit:

There's also this other problem:

template<class T>
void RDAMHandler<T>::clean() {
    long i;
    while(!avtick.empty())
        avtick.pop();
    for(i = v.size() - 1; i >= 0; i--) {
        delete all[i];
        all.pop_back();
        v.pop_back();
    }
}

And the declaration:

template<class T>
class RDAMHandler {
    vector<T*> all;
    priority_queue<long> avtick;
    vector<bool> v;
public:
    T &operator[](long x);
    long insert(T &x);
    void del(long x);
    void clean();
};

I don't see any difference here; what is the problem?

Edit edit: And error

main.obj : error LNK2019: unresolved external symbol "public: void __thiscall RDAMHandler::clean(void)" (?clean@?$RDAMHandler@USDL_Surface@@@@QAEXXZ) referenced in function "void __cdecl cleanUp(class GVar)" (?cleanUp@@YAXVGVar@@@Z)

StelarCF
  • 48
  • 6
  • To track these things down next time from the name the linker gives, use `undname`, which comes with Visual Studio (i.e. use the VS command prompt), the `C++ Name Undecorator`. – 0xC0000022L Jan 27 '14 at 11:05
  • please Check if your `.h` file is included in `VCProject`. For that Check in `Solution Explorer` Pane. – A B Jan 28 '14 at 03:57

2 Answers2

1

They're two different overloads - the declaration in the header has GVar gv, while the definition in the .cpp file has GVar &gv. One of these is probably a typo.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
1

In CParser.cpp

I think You have to use statement

void CParser::parseArg(int argc, char* argv[], GVar &gv)

instead of

void parseArg(int argc, char* argv[], GVar &gv) in CParser.cpp file

And In CParser.h

The declaration should be changed to void parseArg(int argc, char* argv[], GVar &gv);

And For Next Error

For Reference Please Go through this 1. Template using class

Hope this will help you.

A B
  • 1,461
  • 2
  • 19
  • 54
  • Thanks! There's still a problem, which I've edited into the original question. – StelarCF Jan 27 '14 at 11:23
  • I think you are using `cleanup(GVar)` in your code please check it – A B Jan 27 '14 at 11:49
  • Hmm, no, I'm calling an instance of the class. This is what cleanup looks like: void cleanUp(GVar gv) { gv.images.clean(); } and this is how it's called: cleanUp(gv); – StelarCF Jan 27 '14 at 11:54
  • Please Try `template T void RDAMHandler::clean() ` in `cpp` Hope this will help you – A B Jan 27 '14 at 12:07
  • You can go through [This](http://www.cplusplus.com/doc/tutorial/templates/) for more reference – A B Jan 27 '14 at 12:07
  • (sorry for not responding faster) template T void RDAMHandler::clean() gives an error (too many types); I've looked through that reference but I can't find anything that would help; also, here is the declaration of the instance that gives the error: RDAMHandler images; – StelarCF Jan 27 '14 at 12:59