Jump to content
  • Advertisement
Sign in to follow this  
maxest

visual c++ 6 doesn't want to link math

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have a code:
#include <stdio.h>
#include <math.h>

int main()
{
	printf("%f\n",sinf(3.14/6));
	return 0;
}

source file has *.c extension. and when i try to compile this stuff i get linker error: Linking... src.obj : error LNK2001: unresolved external symbol _sinf Debug/OA.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. when i compile the same file but with *.cpp extension the problem doesn't occure. what *.lib file or sth should i add to my C project to use math.h?

Share this post


Link to post
Share on other sites
Advertisement
actually try doing like float integer first

then do
printf("%f", integer);

it may be having trouble with it because of that... or maybe try like doing a sin and see if it says that...

Share this post


Link to post
Share on other sites
Because the problem occurs only with a .c extension, my guess is it has to do with the different calling conventions of C and C++. C++ does "name mangling" to function names to support function overloading. The code you need was probably compiled with the C++ calling convention and you are trying to link it with C's. Sorry but I have no idea how you would fix this if this is the case.

Share this post


Link to post
Share on other sites
Something in your compiler/development environment thinks its a CPP project. And so its using CPP rules for name mangling, so it can't find the symbol. Or something like that - this stuff is pretty esoteric.

You need to tell the compiler to compile using C rules instead of C++ rules and apparently the file extension isn't enough in whatever your tools are.

Share this post


Link to post
Share on other sites
Quote:
Original post by Maxest

source file has *.c extension. and when i try to compile this stuff i get linker error:
Linking...
src.obj : error LNK2001: unresolved external symbol _sinf
Debug/OA.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

when i compile the same file but with *.cpp extension the problem doesn't occure.


sinf() is a C99 extension. I suspect your C compiler does not support the C99 standard but your Cplusplus compiler has (nonstandard) C99 extension support built in.

I can't tell you what the solution is, but it should be okay to compile everything with your Cplusplus compiler instead.

Share this post


Link to post
Share on other sites
my compiler doesn't support C99 standard..? that's a real LOL 'cause i use MS Visual Studio 6! does microsoft have different rules on every way? :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Maxest
my compiler doesn't support C99 standard..? that's a real LOL 'cause i use MS Visual Studio 6! does microsoft have different rules on every way? :)


unfortunately, yes

Share this post


Link to post
Share on other sites
but maybe anyone knows how can i force my VS 6.0 to compile math.h with C project? or maybe should i use gcc with (for example) Code::Blocks?

Share this post


Link to post
Share on other sites
you could upgrade to visual c++ 2005 express its free and preety good IMO

http://msdn.microsoft.com/vstudio/express/visualc/

or maybe you could get the msvc++ 2003 toolkit it has the standard compiler asswell

http://msdn.microsoft.com/visualc/vctoolkit2003/

gcc'll probably work too

Share this post


Link to post
Share on other sites
Quote:
Original post by Maxest
my compiler doesn't support C99 standard..? that's a real LOL 'cause i use MS Visual Studio 6! does microsoft have different rules on every way? :)


VS6 was released in 98. And yes VS6 it very non-standard (at least for C++, assume C also), the never versions (2002, 2003, 2005) are much better (the best available in my opinion) though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!