Problem with Compiling

Ok. So I've tried almost everything suggested on the net about this problem. I've tried using Netbeans, Eclipse, and a few other programs, but nothing works. I keep coming back to Visual Studio and I still can't get this to work.

I've tried changing the linker to Windows and it doesn't work. I get this:

SVCRTD.lib(wcrtexew.obj) : error LNK2019: unresolved external symbol _wWinMain@16 referenced in function ___tmainCRTStartup

Then I change to console and get this:

MSVCRTD.lib(wcrtexew.obj) : error LNK2019: unresolved external symbol _wWinMain@16 referenced in function ___tmainCRTStartup

(I know it's the same thing, but nothing works)
I've had all kinds of weird errors and nothing seems to be working correctly. Any help would be appreciated.

My teacher says the code is right, but I can't seem to get it to compile correctly in any program. I got Minigw installed as well.

/************************************************************/
/* Power Loss in a Transmission Line */
/************************************************************/
/* Defined constants: */
/* POWER – 500 kW */
/* RESIST – 0.05 ohms/mile */
/* Computed Variables: */
/* i – 500/100 and 500/200 */
/* R – 0.05 * 20, 30, …, 100 */
/* ploss – (i * i) * R */
/* Output Variables: */
/* ploss – power loss of current with resistance */
/* volt – volts */
/* mile – distance power traveled */
/************************************************************/
#include <stdio.h>
#include <math.h>
int main ( )
{
const int POWER= 500;
const float RESIST= 0.05;
int volt, mile;
float i, R, ploss;

for (volt = 100; volt <= 200; volt += 100)
{
i = 500/volt;
for (mile = 20; mile <= 100; mile += 10)
{
R = RESIST * mile;
ploss = (i*i) * R;

printf (“Voltage: %3d Miles: %3d Power Loss: %3.2f\n”, volt, mile, ploss);
}
}
return 0;
}
In Visual Studio, you should open the property pages for your project.

You're looking for:

Configuration Properties -> Linker -> System

Under the System tab, the first item listed is Subsystem. Click the little arrow on the right to bring up the listbox and choose "Console (/SUBSYTEM:CONSOLE)". Make sure after you've selected the subsystem that you press the "Apply" button on the bottom right corner or the change won't take effect. After you do this, you should do a clean and build.

Alternately, just start up a new project and begin with the right type of project.
I agree with cire.

Read the error output again. It is linker error occurs when they cannot find where functions are defined.

"Console" program needs "main" function to stratup.

If the program cannot find "main" function, program will give linker error that says similar lines you had with just "WinMain" replaced with "main".

Windows has another form rather than "Console" program, which finds "WinMain" function instead of "main" function.

If your project setting is on "Win32 project", Your program will find "WinMain" instead of "main" function.

You only have main function, though. That is the reason why linker error happens. You didn't defined WinMain function.

Changing the project setting to Console Program will solve the problem.
Last edited on
Thanks for the help so far. I apologize, but I posted the wrong error code for the console (it was late).

Here is what I get when I build the project as a console.

MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

I think I figured it out, cause it wasn't saving my .c file. I had to go back and add my .c as a source file before it would show in the solution explorer. I think it was trying to compile the default powerloss.cpp (which was blank) instead of my powerloss.c.

So once I got all that worked out, this started happening to me (and it happened a few times before when I had the linker set right).

1>------ Build started: Project: PowerLoss, Configuration: Debug Win32 ------
1> ploss.c
1>d:\users\will\documents\visual studio 2010\projects\powerloss\powerloss\ploss.c(21): warning C4305: 'initializing' : truncation from 'double' to 'const float'
1>d:\users\will\documents\visual studio 2010\projects\powerloss\powerloss\ploss.c(27): warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>d:\users\will\documents\visual studio 2010\projects\powerloss\powerloss\ploss.c(33): error C2065: '“Voltage' : undeclared identifier
1>d:\users\will\documents\visual studio 2010\projects\powerloss\powerloss\ploss.c(33): warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
1>d:\users\will\documents\visual studio 2010\projects\powerloss\powerloss\ploss.c(33): warning C4024: 'printf' : different types for formal and actual parameter 1
1>d:\users\will\documents\visual studio 2010\projects\powerloss\powerloss\ploss.c(33): error C2143: syntax error : missing ')' before ':'
1>d:\users\will\documents\visual studio 2010\projects\powerloss\powerloss\ploss.c(33): error C2059: syntax error : 'bad suffix on number'
1>d:\users\will\documents\visual studio 2010\projects\powerloss\powerloss\ploss.c(33): error C2059: syntax error : 'bad suffix on number'
1>d:\users\will\documents\visual studio 2010\projects\powerloss\powerloss\ploss.c(33): error C2017: illegal escape sequence
1>d:\users\will\documents\visual studio 2010\projects\powerloss\powerloss\ploss.c(33): error C2059: syntax error : ')'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

When this happened to me the first time, I thought I had jacked up the code somewhere, but my instructor kept telling me the code was right. So is this some kind of configuration error? I changed the "Compile As" to "Compile as C Code (/TC)" under the advanced settings, but that doesn't seem to fix the errors.

Any suggestions would be appreciated.
If you posted your code within code tags, which you can get using the "<>" button to the right of the edit window, then the lines would be numbered. That way, it would be easier for us to see which line is line 33.

Edit: For some reason, your printf statement is triggering a compiler error - it thinks the word "Voltage" is a code entity rather than part of a string.
Last edited on
how about just reading the error messages ?

they tell you excactly what's the problem
In the code above, the " symbol, as in the little symbol immediately before the capital V of Voltage, and the " after the %3.2f\n are not what they should be, but instead are a completely different symbol that just looks similar.

So, delete those symbols, write them in yourself again using your own keyboard, and don't copy and paste code from wherever you got that.

Put more simply, you've got and where you should have "
Last edited on
@Moschops Thank you very much!! That has been my problem all along. My class doesn't require us to compile the code, but instead they just have us submit the code in a Word document. So I was writing everything in Word, then just copying and pasting the text into the file.

@Mikeyboy I apologize, I will remember to add the line tags next time.
Topic archived. No new replies allowed.