Sign in to follow this  

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.

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
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
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
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
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
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.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this