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

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

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 on other sites
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 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 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 on other sites
Quote:
 Original post by Maxestsource file has *.c extension. and when i try to compile this stuff i get linker error:Linking...src.obj : error LNK2001: unresolved external symbol _sinfDebug/OA.exe : fatal error LNK1120: 1 unresolved externalsError 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 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 on other sites
Quote:
 Original post by Maxestmy 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 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 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 on other sites
Quote:
 Original post by Maxestmy 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 on other sites
thank for your help. i think i will be using code::blocks. i see it very comfortable IDE which use compiler consistent with C99 :)
besides, i want to code a game for free so at least it excludes all ms visual studios

Share on other sites
Yeah, go Code::Blocks.

On to the topic, GCC implements the standard C99. Unfortunately, trying out tests with MSVS2k5E shows that it doesnt implement C99.

Just what I see, don't quote me :).

C++

Share on other sites
everything would be fine with code::blocks if it wasn't for a fact, that SDL doesn't want to go.. :(
if anyone knows how to solve that problem, plase, look at it: http://www.gamedev.net/community/forums/topic.asp?topic_id=369526

Share on other sites

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

Create an account

Register a new account

• Forum Statistics

• Total Topics
628674
• Total Posts
2984160

• 13
• 12
• 10
• 9
• 9