Problem with SetSuspendState - c++

I write a small application to enter the computer to Standby Mode:
#include "stdafx.h"
#include <windows.h>
#include <PowrProf.h>
int _tmain(int argc, _TCHAR* argv[])
{
SetSuspendState(FALSE, FALSE, FALSE);
return 0;
}
I get this error:
1>Standby.obj : error LNK2001: unresolved external symbol _SetSuspendState#12
1>C:\Documents and Settings\Sobak\Desktop\Standby\Release\Standby.exe : fatal error LNK1120: 1 unresolved externalsexternals
How can I fix it?
P.S.
I use Visual Studio 2005
Thank you in advance.

You should link your programm with the PowrProf.lib library. You could do it by adding the following string:
#pragma comment(lib, "PowrProf.lib")

Related

LNK2001 error on atoi and stoi function with proper includes added

I have this project that throws LNK2001 error on using atoi while proper includes added:
#... //other headers
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <iostream>
BOOL main(int argc, char* argv[]){
ShowNumber(atoi(argv[1]));
return TRUE;
}
Error is: LNK2001: Unresolved external symbol _atoi
I do know that LNK error happens while a header confusion occurs. But i don't think that headers are the problem here. Is there anything in the project configuration or header conflict that may cause this to break? Also i get 15 other LNK2001 on using std::stoi.
Visual studio 2017 with 2015 or 2017 toolset.

SDL unresolved external symbol

I keep getting these errors:
error LNK2005: _main already defined in main.obj
error LNK2019: unresolved external symbol _SDL_main referenced in function _main_utf8
error LNK1120: 1 unresolved externals
when building this
#include <stdio.h>
#include <SDL.h>
int main(int argc, const char* argv[]){
printf("Hi\n");
return 0;
}
I've set up the directories and the linker in Visual Studio 2013, but I can't figure out what went wrong. I'm using the 32 bit SDL runtime library. I'm also fairly new to C++.
Before your main function, define
#define SDL_MAIN_HANDLED
This stops SDL's "service" of parsing the command line for you(only on windows). Though this is a fix, this isn't good for cross platform programs. The other fix is to change main so that it looks like this:
int main(int argc, char* argv[])
You must do this because of the main macro defined in SDL_Main.h that forces you to have exactly that otherwise it will give you the error you have.

error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup and Error 2 error LNK1120: 1 unresolved externals

I am getting the two errors when I try to compile my code. I have defined win32 consile application. I have not even yet started coding. My configurations are the following - Linker - subsytem - Console; Linker - Advanced - Entry Point - Blank.
error LNK2019: unresolved external symbol _main referenced in function
___tmainCRTStartup
Error 2 error LNK1120: 1 unresolved externals
I don't know what happened. Before everything was working fine but from today it does not. Do you have any idea how I can resolve it that?
My code so far is
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "tbb/blocked_range.h"
#include "tbb/tbb.h"
#include <stdio.h>
#include <math.h>
#include <iostream>
#include "tbb/parallel_for.h"
#include <sstream>
#include <tbb/task_scheduler_init.h>
using namespace std;
#define PI 3.14159265
using namespace tbb;
// Sequential Execution
class Sequential
{
double * m;
double *n;
public:
Sequential(double n[], double m[]): n(n), m(m){}
void Partition()
{
}
int main(int argc, char** argv)
{
//double a = 5;
//double b = 4;
//Sequential g = Sequential(a,b);
return 0;
}
};
Thanks
The main function must be in the global namespace. C++ is not C#/Java where all functions must be inside classes.

codegen matlab to c++ :- Problems when attempting to build a c++ based .exe rather than c?

I am having a few problems with using codegen (via the gui interface).
I have successfully built a very simple c based .exe program based on the following two files.
coderand.m
function r = coderand() %#codegen
r = rand();
main.c
#include <stdio.h>
#include <stdlib.h>
#include "coderand.h"
int main()
{
printf("coderand=%g\n", coderand());
return 0;
}
If I now try and change out main.c for the same code in a main.cpp,
main.cpp
#include <stdio.h>
#include <stdlib.h>
#include "coderand.h"
void main(int argc, char **argv)
{
printf("coderand=%g\n", coderand());
}
I get the following compile errors.
main.obj : error LNK2019: unresolved external symbol "double __cdecl coderand(void)" (?coderand##YANXZ) referenced in function _main 25 F:\CoderTest\coderand.exe : fatal error LNK1120: 1 unresolved externals
Any help much appreciated.
Edit:- Solved by myself...
For those suffering the same problem...
Coder -> More Settings -> All Settings -> Advanced -> Language..change C to C++
C++ can call C functions without difficulty, you just have to let the compiler know that the C calling convention applies to this function, like so:
extern "C" {
# include "coderand.h"
}

Unresolved external symbol in c++

#include <iostream>
#include <cstdlib>
using std::cout;
using std::endl;
using std::rand;
int man(){
int t=rand();
cout<<t<<endl;
return 0;
}
here is code for generate random number in c++ and i have mistake
1>c:\users\david\documents\visual studio 2010\Projects\random_function\Debug\random_function.exe : fatal error LNK1120: 1 unresolved externals
please help
Change man() to main().
Me, I think I'd change "man" to "main" and see what happens...