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:
Related
I am following a tutorial here for creating a static library and using it for another project. So I want to create a .lib file and use it for another project.
Static library project:
MyMathLib.h
#define PI 3.1415;
double PowerOf2(double UserNumber);
double PowerOf3(double UserNumber);
double CircleArea(double UserRadius);
double CircleCircum(double UserRadius);
MyMathLib.cpp
#include "stdafx.h"
#include "MyMathLib.h"
double PowerOf2(double UserNumber) { return UserNumber * UserNumber; }
double PowerOf3(double UserNumber) { return UserNumber * UserNumber * UserNumber; }
double CircleArea(double UserRadius) { return UserRadius * UserRadius * PI; }
double CircleCircum(double UserRadius) { return 2 * UserRadius * PI; }
For the second project, I have done the following:
Add the MyMathLib vc project
Common Properties -> References -> Add New Reference
C/C++ -> General -> Additional Include Directories.
This is the C file that tries to call the library:
MyApps1.c
#include <stdio.h>
#include "MyMathLib.h"
int main()
{
double p2 = 10.0;
double radius = 4.0;
printf("The number %.2f to the power of 2 is %.2f. \n", p2, PowerOf2(p2));
printf("A circle with a radius of %.2f, the area is %.2f. \n", radius, CircleArea(radius));
return 0;
}
The error I am getting is:
1>------ Build started: Project: MyApps1, Configuration: Debug Win32 ------
1>MyApps1.obj : error LNK2019: unresolved external symbol _PowerOf2 referenced in function _main
1>MyApps1.obj : error LNK2019: unresolved external symbol _CircleArea referenced in function _main
1>c:\users\bandika\documents\visual studio 2013\Projects\MyApps1\Debug\MyApps1.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
So there is a linking error somewhere. I have tried going to MyApps1 Properties -> Linker -> Input -> Additional Dependencies but I don't think I can add the .lib file for MyMathLib. Any idea what I'm missing?
Its related to linking of your static lib with the second project.
I don't see any problem in adding your generated static library name in "Configuration Properties -> Linker -> Input -> Additional Dependencies".
It should solve the linking problem.
Are you facing any other problem after using this option?
You do not have the second file added to the project in the VS.
I'm trying to use Protobuf in C++, but having trouble getting it to do anything meaningful. I'm using Visual Studio 2015.
I built the protobuf library. I'm using the latest version from github.
I have created a .proto file as such:
syntax = "proto3";
package Networking;
message Robot{
message KinematicLinkProto {
string name = 1;
float x_pos = 2;
float y_pos = 3;
float z_pos = 4;
float roll = 5;
float pitch = 6;
float yaw = 7;
float x_scale = 8;
float y_scale = 9;
float z_scale = 10;
}
repeated KinematicLinkProto links = 1;
}
I compile this, and try to add it to a project:
#include "Robot.pb.h"
int main(int argc, char **argv)
{
Networking::Robot robot_message;
return 0;
}
My linker links libprotobuf.lib. I am building it as /MD and libprotobuf is built as /MD.
For some reason, this simple program has the following two linker errors:
Error LNK2019 unresolved external symbol "private: static bool google::protobuf::io::CodedOutputStream::default_serialization_deterministic_" (?default_serialization_deterministic_#CodedOutputStream#io#protobuf#google##0_NA) referenced in function "public: virtual unsigned char * __cdecl Networking::Robot::SerializeWithCachedSizesToArray(unsigned char *)const " (?SerializeWithCachedSizesToArray#Robot#Networking##UEBAPEAEPEAE#Z)
Error LNK2019 unresolved external symbol "class google::protobuf::internal::ExplicitlyConstructed<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > google::protobuf::internal::fixed_address_empty_string" (?fixed_address_empty_string#internal#protobuf#google##3V?$ExplicitlyConstructed#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###123#A) referenced in function "protected: void __cdecl google::protobuf::internal::RepeatedPtrFieldBase::Clear<class google::protobuf::RepeatedPtrField<class Networking::Robot_KinematicLinkProto>::TypeHandler>(void)" (??$Clear#VTypeHandler#?$RepeatedPtrField#VRobot_KinematicLinkProto#Networking###protobuf#google###RepeatedPtrFieldBase#internal#protobuf#google##IEAAXXZ)
I'm very confused - this is a very simple program. What could I possibly be doing wrong?
EDIT: A colleague compiled proto 3001000. This version does seem to work. I'm curious as to what about 3002000 breaks everything.
If you are using DLL, use
#define PROTOBUF_USE_DLLS
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
I'm trying to get this accurate timer working on VS2008, on Windows XP (and eventually Server 2008) from the following example:
http://technology.chtsai.org/w98timer/
However I get the following errors:
error LNK2019: unresolved external symbol _imp_timeEndPeriod#4
error LNK2019: unresolved external symbol _imp_timeGetTime#0
error LNK2019: unresolved external symbol _imp_timeBeginPeriod#4
error LNK2019: unresolved external symbol _imp_timeGetDevCaps#8
Could anybody please advise?
I just want a simple, accurate, millisecond-timing example for C++ on Windows.
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include "stdafx.h"
void
main (void)
{
TIMECAPS resolution;
DWORD start, finish, duration, i;
if (timeGetDevCaps (&resolution, sizeof (TIMECAPS)) == TIMERR_NOERROR)
{
printf ("Minimum supported resolution = %d\n", resolution.wPeriodMin);
printf ("Maximum supported resolution = %d\n", resolution.wPeriodMax);
}
if (resolution.wPeriodMin <= 1)
{
if (timeBeginPeriod (1) == TIMERR_NOERROR)
{
for (i = 100; i <= 120; i++)
{
start = timeGetTime ();
while (timeGetTime () < (start + i));
finish = timeGetTime ();
duration = finish - start;
printf ("expected:%d actual:%ld\n", i, duration);
}
timeEndPeriod (1);
}
}
}
As MSDN suggests you need to include winmm.lib into the project. So add the following line anywhere into your source code:
#pragma comment(lib, "winmm.lib")
Looking at the docs it looks like you need to add Winmm.lib to the additional libraries to link in your project properties.
You need to add winmm.lib to your linker dependencies.
These functions are defined in winmm.dll. You need to add winmm.lib to your link list.
I am performing a project with ITK for processing medical images. After a lot of work there is no further compilation errors, but in the linking process I am having the following info :
1>------Generation started: proyect: prueba_r01, configuration: Debug Win32 ------
1>Linking…
1>Creating library C:\Documents and Settings\GTTS\Mis documentos\Visual Studio 2008\Projects\prueba_r01\Debug\prueba_r01.lib and object C:\Documents and Settings\GTTS\Mis documentos\Visual Studio 2008\Projects\prueba_r01\Debug\prueba_r01.exp
1>prueba_r01.obj : error LNK2019: extern symbol "public: double (* __thiscall prueba_r01::multiply_matrix_2D(double ()[2],double ()[2],int,int))[2]" (?multiply_matrix_2D#prueba_r01##QAEPAY01NPAY01N0HH#Z) unresolved which is referenced in the function "private: void __thiscall prueba_r01::filtro(void)" (?filtro#prueba_r01##AAEXXZ)
1>C:\Documents and Settings\GTTS\Mis documentos\Visual Studio 2008\Projects\prueba_r01\Debug\prueba_r01.exe : fatal error LNK1120: 1 externos sin resolver
1>prueba_r01 - 2 errors, 0 warnings
========== Generar: 0 corrects, 1 incorrects, 0 actualized, 0 omited ==========
The method multiply_matrix_2D produces the error when is called inside the private slot “filtro()” (translated as filter)
The header of the file is :
#include <QtGui/QMainWindow>
#include "ui_prueba_r01.h"
#include "vicdef.h"
#include "itkImage.h"
#include "math.h"
#include <complex>
#include "fftw3.h"
using namespace std;
#define PI 3.14159265
class prueba_r01 : public QMainWindow
{
Q_OBJECT
public:
typedef double PixelType;
typedef itk::Image < PixelType, 2> ImageType;
ImageType::Pointer imagen;
double** H;
prueba_r01(QWidget *parent = 0, Qt::WFlags flags = 0);
~prueba_r01();
void matrix2D_H(int ancho, int alto, double eta, double sigma);
fftw_complex* multiply_matrix_2D(fftw_complex* out, fftw_complex* H,int a, int b);
private slots:
void openRGB();
void filtro();
private:
Ui::prueba_r01Class ui;
};
#endif // PRUEBA_R01_H
And the main part where the problem is located is in the .cpp file and is displayed here:
fftw_complex* res ;
res = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*a*b);
fftw_complex* H_casted= reinterpret_cast<fftw_complex*> (&H);
res = multiply_matrix_2D(out,H_casted, a, b);
The process of casting a **double pointer to *fftw_complex is done here, because I want to multiply a filter in frequency domain (H(w)) with the result of the fft transform of an image, that’s the reason. Is important to remark that fftw_complex is double[2], the first row for the real part, and the second for the imaginary
And the problematic method is shown below:
fftw_complex* multiply_matrix_2D(fftw_complex* out, fftw_complex* H, int a ,int b){
/* The matrix out[axb] or [n0x(n1/2)+1] is the image after the FFT , and the out_H[axb] is the filter in the frequency domain,
both are multiplied POINT TO POINT, it has to be called twice, one for the imaginary part and another for the normal part
*/
fftw_complex *res;
res = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*a*b);
for (int i0 = 0; i0<a ; i0++){
for (int i1 = 0; i1<b ; i1++){
res[i1+a*i0][0] = out[i1+a*i0][0]*(H[0][0]+H[0][1]); // real part
res[i1+a*i0][1] = out[i1+a*i0][1]*(H[0][0]+H[0][1]); // imaginary part
}
}
return res;
}
Any help will be really nice!! I’m quite lost now…
Thanks! Gracias!
Antonio
Change the function header in the cpp file to:
fftw_complex* prueba_r01::multiply_matrix_2D(fftw_complex* out, fftw_complex* H, int a, int b)
You forgot the class name (prueba_r01::) in the implementation, therefore it doesn't find the function body