Skip to main content
gamedev.net
🔒 Locked

using Complex with visual studio

Started by PDHB 7 replies 1.3k views
Original Post
PDHB
PDHB
When I try to include <Complex> in a C++ file, as in #include "stdafx.h" #include <complex> using namespace std; I get Ellipsometry fatal error LNK1120: 2 unresolved externals Ellipsometry error LNK2020: unresolved token (0A000006) _CxxThrowException Ellipsometry error LNK2020: unresolved token (0A000016) delete I can use other headers, such as <cmath> just fine. When I download code that uses <complex> it compiles fine. I can copy the project file to another, remove the code, and write minr in ti's place, and generally it will work. But if I cut all code from another project that uses <complex> and paste it into mine, It doesn't work. And yes, the header file is there. How do I fix this ?
Behold the nascent power of Semejant!
Qw3r7yU10p!
Qw3r7yU10p!
That's not a compiler error it's a linker error. That isn't anything to do with <complex>

#include <complex>#include <iostream>int main() {    std::complex<double> c(1.4, 5.7);    std::cout << c << std::endl;    return 0;}


make an empty project with this and tell me what it produces.
PDHB
PDHB
Hmm. It works. Why won't it work in a class library ?
Behold the nascent power of Semejant!
Qw3r7yU10p!
Qw3r7yU10p!
Maybe it is something to do with whether exceptions are enabled in your project. I don't know what environment you're using but there is often an option to enable/disable exceptions. If the code you are copying across uses exceptions then the project it's from will have them enabled. This is quite likely the problem.
PDHB
PDHB
I'm using Visual Studion 2003. I get the same problem when I try typing into a class library or a windows project source code.

When I add an unmanaged class it works fine in the unmanaged class.
Behold the nascent power of Semejant!
Qw3r7yU10p!
Qw3r7yU10p!
Quote:
Original post by PDHB
I get the same problem when I try typing into a class library or a windows project source code.


You need to be a little clearer.

Did you check about the exceptions? It'll probably be in project->settings although I don't have VS 2003 myself.
PDHB
PDHB
Yes, Exceptions are enabled.

What I meant was that any time I try to include <complex> in a managed code file I get these link errors. The example of copying someone else's code from a project that worked into mine, where it does not work, was to show that it isn't what I am typing that is causing the problems.
Behold the nascent power of Semejant!
Qw3r7yU10p!
Qw3r7yU10p!
std::complex is all in the header file. you don't need to link with anything to make it work.

If you are getting link errors it is because you are using something but haven't told the linker about the libraries it needs to link against.

I searched for the error you are getting and found this at the top of the list of 3 results.

Quote:
>>error LNK2020: unresolved token _CxxThrowException
>>error LNK2020: unresolved token delete

Assuming a managed C++ dll, add MSVCRT.LIB (Release) and MSVCRTD.LIB (Debug) to your Linker project settings, under Additional Dependencies. This will fix the unresolved errors


As I say, I don't have VS2003 but I do have [google]. Hope that helps.

Pete
PDHB
PDHB
Works great. Thank you
Behold the nascent power of Semejant!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.