Error when using GetPwrCapabilities - c++

I am trying to run the following code to read the max processor throttle:
#include <iostream>
#include <string>
#include <tchar.h>
#include <windows.h>
#include <Powerbase.h>
#include <PowrProf.h>
using namespace std;
int main()
{
SYSTEM_POWER_CAPABILITIES sysc;
while (GetPwrCapabilities(&sysc)) {
cout << " Your Max Throttle is: " << static_cast<double> (sysc.ProcessorMaxThrottle) << endl;
}
Sleep(10000);
return 0;
}
However , I am receiving the following error:
...error LNK2019: unresolved external symbol _GetPwrCapabilities#4 referenced in function _main
...fatal error LNK1120: 1 unresolved externals
I tried the solution related to make sure the linker set to console program but it does not work. Any suggestion ?
I am using MSVS 2013.
Thanks

To make it work, you need to add PowrProf.lib to your project setting:
Project Properties -> Linker -> Input -> Additional Dependencies

Related

Getting Linking errors using BLuetoothAPIs.h in vs 2017 and windows 10

Using the following code:
// Bluetooth_test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include "bthdef.h"
#include "BluetoothAPIs.h"
int main()
{
BLUETOOTH_DEVICE_SEARCH_PARAMS bptsp;
// set options for how we want to load our list of BT devices
bptsp.dwSize = sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS);
bptsp.fReturnAuthenticated = TRUE;
bptsp.fReturnRemembered = TRUE;
bptsp.fReturnUnknown = TRUE;
bptsp.fReturnConnected = TRUE;
bptsp.fIssueInquiry = TRUE;
bptsp.cTimeoutMultiplier = 4;
bptsp.hRadio = NULL;
BLUETOOTH_DEVICE_INFO bptdi;
bptdi.dwSize = sizeof(bptdi);
HBLUETOOTH_DEVICE_FIND hFind = BluetoothFindFirstDevice(&bptsp, &bptdi);
BluetoothFindDeviceClose(hFind);
return 0;
}
I get the following errors:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _BluetoothFindFirstDevice#8 referenced in function _main Bluetooth_test D:\VS 2017\repos\Bluetooth_test\Bluetooth_test\Bluetooth_test.obj 1
Error LNK1120 2 unresolved externals Bluetooth_test D:\VS 2017\repos\Bluetooth_test\Debug\Bluetooth_test.exe 1
Error LNK2019 unresolved external symbol _BluetoothFindDeviceClose#4 referenced in function _main Bluetooth_test D:\VS 2017\repos\Bluetooth_test\Bluetooth_test\Bluetooth_test.obj 1
I am pretty new to C++ and I have no clue why it won't compile please help me
Windows API's:
https://learn.microsoft.com/en-us/windows/win32/api/bluetoothapis/nf-bluetoothapis-bluetoothfindfirstdevice
https://learn.microsoft.com/en-us/windows/win32/api/bluetoothapis/nf-bluetoothapis-bluetoothfinddeviceclose
==== EDIT ====
Like Mike Petrichenko said in the comments, the errors won't acure when I add #pragma comment(lib, "Bthprops.lib"); underneath the includes.

Added opencv_world400.lib and opencv_world400d.lib to dependencies, still getting LNK2001 errors

I've added opencv_world400.lib and opencv_world400d.lib to the dependencies, but I'm still getting this error in MSVS2017:
1>------ Build started: Project: OpenCLTest, Configuration: Release x64 ------
1>OpenCLTest.obj : error LNK2001: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd#cv##YAHPEAHH#Z)
1>c:\users\chubak\documents\visual studio 2017\Projects\OpenCLTest\x64\Release\OpenCLTest.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "OpenCLTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
There were no other lib files in the folder, just those two. What causes this problem I don't know.
Here's the code:
#include "stdafx.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat image = imread("C:\\Users\\Chubak\\Pictures\\index.jpg");
if (image.empty())
return -1;
imshow("TEST", image);
waitKey();
return 0;
}
3 steps:
1. C++ -> General -> Additional Include Directories
2. Linker -> Input -> Additional Dependencies
3. Linker -> General -> Additional Include Directories

VS 2015 unresolved external symbol error

This error was thrown by my code:
1>MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol WinMain referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
1>C:\Users\thequantumforge\Desktop\scripts\Visual Studio 2013\Projects\newtonsmethod\x64\Debug\newtonsmethod.exe : fatal error LNK1120: 1 unresolved externals
The code is as follows:
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <cfloat>
#include <chrono>
using namespace std;
const long double h = LDBL_EPSILON;
long double equation(long double x) {
return (pow(x, 3) - x + 1);
}
long double intercept(long double x) {
// x_n+1 = xn - f(xn)/f'(xn)
long double deriv = (equation(x + h) - equation(x)) / h;
if (deriv == 0)
{
x += h;
return (x - equation(x) / ((equation(x + h) - equation(x)) / h));
}
return (x - equation(x) / deriv);
int main() {...}
It worked in Code::Blocks using the C++11 compiler, so I'm not sure why it isn't working with Visual Studio 2015. I tried looking at other answers, but those were either unclear or were for other versions of Visual Studio. I did some research and found out that it's supposed to be caused by a misspelling of the main() function, but that doesn't seem to be the case. I tried declaring the function prototypes first then defining them after main(), but the result is the same.
Change your solution into a console application in the linker => system section:

C++ Connector to MySQL

EDITED:
My Problem is the errors at the bottom of this post.
Heres my additional include directories
C:\Program Files\boost
C:\Program Files\MySQL\MySQL Connector C++ 1.1.3\include
C:\Program Files\MySQL\MySQL Server 5.6\include
Additional Library Directories
C:\Program Files\MySQL\MySQL Server 5.6\lib
C:\Program Files\MySQL\Connector C++ 1.1.2\lib\opt
Additional Dependencies
libmysql.lib
mysqlcppconn-static.lib
Heres my code
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
#include <stdlib.h>
#include <Windows.h>
#include <mysql.h>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#define host "localhost"
#define username "root"
#define password "root"
#define database "tests"
int main()
{
MYSQL* conn;
conn = mysql_init( NULL );
if( conn )
{
mysql_real_connect( conn, host, username, password, database, 0, NULL, 0 );
}
MYSQL_RES* res_set;
MYSQL_ROW row;
unsigned int i;
mysql_query( conn, "SELECT * FROM tbl_clients WHERE id = 1" );
res_set = mysql_store_result( conn );
unsigned int numrows = mysql_num_rows( res_set );
if( numrows )
{
row = mysql_fetch_row( res_set );
if( row != NULL )
{
cout << "Client ID : " << row[0] << endl;
cout << "Client Name: " << row[1] << endl;
}
}
if( res_set )
{
mysql_free_result( res_set );
}
if( conn )
{
mysql_close( conn );
}
return 0;
}
These are the errors I get
1>------ Build started: Project: okay, Configuration: Debug Win32 ------
1>welp.obj : error LNK2019: unresolved external symbol _mysql_num_rows#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_init#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_real_connect#32 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_query#8 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_store_result#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_free_result#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_fetch_row#4 referenced in function _main
1>welp.obj : error LNK2019: unresolved external symbol _mysql_close#4 referenced in function _main
1>C:\Users\Damian\documents\visual studio 2012\Projects\okay\Debug\okay.exe : fatal error LNK1120: 8 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please help, This project is due in about 48 hours for my class, and I've spent so much time trying to figure this out.
Thanks
respectfully, your last two questions are compiler/linker questions. I understand your frustration, as I knew how to code early but knew nothing about compilers/linkers. When you get a moment take some time to read about:
headers
binary vs object file
libraries / shared object
compiler
linker
function mangling (C vs C++)
To answer your question, I am guessing you're doing this in Microsoft Visual Studio:
You need to go to Project Properties and set Additional Library Paths (i see you did that from your last post)
You need to specify the library, I'm going out on a limb here and assuming it will mysql.lib ... There's an "Additional Library" input somewhere in the Linker section, you'll be able to identify it because kernel32.lib will be int it. Add the mysql.lib to that section. Confirm the name by going to the mysql folder which holds the binaries.
Make sure you're using the static library, the .dll will give you new issues that you don't need to worry about. This is usually achieved by setting the correct library directory. Many c++ libraries will ship with precompiled "Static" and "Dynamic" folders containing the correct libraries.
This is error is happening due to linker problem. The linker is not able to find the required static or dynamic libraries (mysql.lib,mysqlcppconn-static.lib,libmysql.dll and libmysql.lib). The additional lib setting is wrong. Check this site give the path correctly Building MySQL Connector/C++ Windows Applications with Microsoft Visual Studio

LNK2019: Error. unresolved external symbol in C++ program using InternetOpen InternetReadFIle

I have tried writing a simple program to get information from a website. I can't compile as I get the LNK2019 error for InternetReadFile, InternetOpenUrl, etc. and e.g.
1>GetInternetInfo.obj : error LNK2019: unresolved external symbol _imp_InternetReadFile#16 referenced in function _main
I assume that means I did not define these functions, that I did not include the correct library. I thought including #include would fix it, but it does not seem to help. I am running this on Visual Studio 2010 using C++. Below is my program. Any help is appreciated.
#include <string>
#include <iostream>
#include <fstream>
#include <windows.h>
#include <wininet.h>
#include <winsock.h>
#include <stdio.h>
#include <stdarg.h>
using namespace std;
int main()
{
HINTERNET hOpen, hURL;
LPCWSTR NameProgram = L"Webreader"; // LPCWSTR == Long Pointer to Const Wide String
LPCWSTR Website;
char file[101];
unsigned long read;
//Always need to establish the internet connection with this funcion.
if ( !(hOpen = InternetOpen(NameProgram, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 )))
{
cerr << "Error in opening internet" << endl;
return 0;
}
Website = L"http://www.google.com";
hURL = InternetOpenUrl( hOpen, Website, NULL, 0, 0, 0 ); //Need to open the URL
InternetReadFile(hURL, file, 100, &read);
while (read == 100)
{
InternetReadFile(hURL, file, 100, &read);
file[read] = '\0';
cout << file;
}
cout << endl;
InternetCloseHandle(hURL);
return 0;
}
Please include "Wininet.lib" in your project settings.
Project->Properties->Configuration Properties->Linker->Input->Additional Dependencies
You can also add this line to your code after include section instead of adding library to the properties:
#pragma comment(lib, "wininet.lib")
Did you link to wininet.lib?
http://msdn.microsoft.com/en-us/library/aa385103(VS.85).aspx