-1

I´m a linux user and I dont have much experience with programming under Windows so i pressume it's a problem with Visual Studio, which i have to use, or something like that...

I have really simple code like that:

myProgram.cpp

...
#include "rideList.h"
...
int main() {
   ...
   rideListMain();
   ...
}

rideList.h

...
void rideListMain();
...

rideList.c

void rideListMain() {
   // some code here...
}

In fact there are another 4 files and similar functions like the rideListMain() and the compiler's output is

LNK2019 unresolved external symbol "void __cdecl rideListMain(void)" (?rideListMain@@YAXXZ) referenced in function _main

Solution

Renaming *.cpp to *.c solved the problem.

sukovanej
  • 658
  • 2
  • 8
  • 18
  • 2
    `rideList.c` possible name mangling issue. I mean did you forget an `extern "c" {` http://stackoverflow.com/questions/1041866/in-c-source-what-is-the-effect-of-extern-c – drescherjm Jan 23 '17 at 17:51
  • 2
    you mixed `c` with `C++` – Raindrop7 Jan 23 '17 at 17:51
  • 1
    C and C++ are different languages. – too honest for this site Jan 23 '17 at 17:52
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – too honest for this site Jan 23 '17 at 17:53
  • Please post a complete but minimal example that readers can try. "derscherjm"´s comment is likely the explanation, but still. – Cheers and hth. - Alf Jan 23 '17 at 17:58
  • Thanks a lot, I wouldn't have thought that the compiler output depends on a main file extension ... I mean it recognises the main file correctly (it doesn't care about the extension) but during the compilation it somehow depends on the extension. – sukovanej Jan 23 '17 at 17:59
  • Did you build this successfully on Linux, since you're blaming your tools so confidently? – molbdnilo Jan 23 '17 at 18:00
  • ***I wouldn't have thought that the compiler output depends on a main file extension*** If you give it a `.c` extension msvc will compile your source file as a `c` source file instead of a `c++` source file. Other compilers will do that also. – drescherjm Jan 23 '17 at 18:01
  • Rename the file from `rideList.c` to `rideList.cpp`. That tells the compiler that it's C++ code, not C. – Cheers and hth. - Alf Jan 23 '17 at 18:07
  • That's it, thanks again. And also thanks for the downvotes. I'm glad for the people there who can express their dissatisfaction and the stupidity of my question... but you know what? I don't care! I just learnt something new and I also found my solution. Isn't that what this website is for... – sukovanej Jan 23 '17 at 18:24

1 Answers1

3

You're including the header file once in a .cpp file, thus mangling the name as expected by standard C++ implementations, and then including the same header file in a .c file when actually defining your class, thus defining it with the name unmangled.

As the linker tells you very clearly, ?rideListMain@@YAXXZ was never defined.

i pressume it's a problem with Visual Studio

Nope, it's a problem with your understanding of C and C++ both. extern "C" will declare the type name unmangled in a .cpp unit if that's what you wish.

Blindy
  • 65,249
  • 10
  • 91
  • 131