Visual C++ 2013 lnk2019 error - visual-c++

I am just getting started with visual cpp 2013 . I looked around the web for tutorials and tried running the following code.
#include <windows.h>
#include <tchar.h>
int WINAPI winMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
MessageBox(NULL, _T("Hello World"), _T("A Sample Application"), MB_ICONINFORMATION);
return 0;
}
It throws the following error
Error 1 error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup C:\Users......\MSVCRTD.lib(crtexew.obj) SampleApp
Can anyone tell me what am i doing wrong here and can someone suggest site for latest tutorials (besides msdn).

I think Raymond Chen already answered your question, but you don't think so. Let me try it again.
From your code, you misspelled 'wWinMain'. The correct one has 8 characters, yours have only 7 characters. You see, that is the problem.
I tried it in VS 2013: replacing your winMain with wWinMain. Project built and ran without problem. Please, try it again.

Related

<iostream> and #define __STDC_WANT_SECURE_LIB__ 0 results in error C2039: 'sprintf_s'

When building this very simple test program
#include <iostream>
int main() {
std::cout << "x";
}
with visual studio 2019 and /Wall I'm getting a
warning C4668: '__STDC_WANT_SECURE_LIB__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
Trying to
#define __STDC_WANT_SECURE_LIB__ 0
before including iostream results in
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xlocnum(1388,69): error C2039: 'sprintf_s': is not a member of '`global namespace''
at least for my VS. Godbolt doesn't complain.
#define __STDC_WANT_SECURE_LIB__ 1
is fine and doesn't let the compiler complain about sprintf_s which one would expect.
Microsoft doesn't show me any results when searching for it.. SO does here but overall i can't find many resources on if and how to use that define.
Is there a way to disable the secure extensions and include <iostream> ? Am i using the wrong define or approach for this?

gmock and gtest linker errors in vc++ 2015 community edition

I'm tyring to configure gmock/gtest in vc++ 2015, namely
downloaded gmock and gtest
added E:\googlemock\googletest\include and E:\googlemock\googlemock\include in VC++ include directories.
compiled gmock.sln and added E:\googlemock\googlemock\msvc\2015\Debug to the Library directories.
added gmock.lib to Linker -> Input Additional dependencies.
And on building I'm getting a bunch of linker errors as below.
As i don't have any clue about the gmock/ gtest code. How shall I reason / proceed further in fixing these problems ?
code:
int main(int argc, char **argv)
{
testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}
Error **LNK2038** mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in ArrayOperations.obj ConsoleApplication3 E:\projects\cpp\ConsoleApplication3\ConsoleApplication3\gmock.lib(gtest-all.obj)
Error **LNK2005** "public: bool __thiscall std::ios_base::good(void)const " (?good#ios_base#std##QBE_NXZ) already defined in gmock.lib(gtest-all.obj) ConsoleApplication3 E:\projects\cpp\ConsoleApplication3\ConsoleApplication3\msvcprtd.lib(MSVCP140D.dll) 1
and more bunch of errors on the same LNK category*
Finally I could solve the problem by adding in properties -> c++ code generation
Run time Library to Multi-threaded Debug (/MTd) as from the post.
Mismatch Detected for 'RuntimeLibrary'

Multi threading in borland

I'm programming c++ in Borland c++ 5.02. I'm trying to run this code:
#include <stdio.h>
#include <pthread.h>
#define NUM 5
main()
{
pthread_t t1, t2; /* two threads */
void *print_msg(void *);
pthread_create(&t1, NULL, print_msg, (void *)"hello");
pthread_create(&t2, NULL, print_msg, (void *)"world\n");
pthread_join(t1, NULL);
pthread_join(t2, NULL);
}
But I get this error:
Info :Compiling C:\BC5\BIN\noname00.cpp
Error: noname00.cpp(2,2):Unable to open include file 'PTHREAD.H'
Error: noname00.cpp(8,15):Undefined symbol 'pthread_t'
Error: noname00.cpp(8,15):Statement missing ;
Error: noname00.cpp(12,18):Call to undefined function 'pthread_create'
I highlighted the main error which is caused by 'PTHREAD.H'. I checked the include folder for this file. It doesn't exist. How can I fix this problem?
Borland's C++ toolchain doesn't include a pthreads library, nor does the Windows SDK. You'll either need to use native Win32 thread APIs or get a 3rd party pthreads implementation for Windows.
Some options include:
winpthreads.h: http://locklessinc.com/articles/pthreads_on_windows/
pthreads-win32: https://www.sourceware.org/pthreads-win32/
I have no idea how well those things work with Borland C++ 5.x.
Another alternative is to use a toolchain that includes a pthreads implementation, such as TDM's MinGW toolchain:
http://tdm-gcc.tdragon.net/
your problem is #include <pthread.h>
you need either copy all the pthread related files (.h,.c,.cpp,.hpp,.lib,.obj)
into compiler include folder
or add include path to it in your project/compiler settings
or copy it locally to your project and change #include <pthread.h> to #include "pthread.h"
So compiler did not find the pthread.h header
so no datatype from it is known from compiler side (like pthread_t)
therefore the rest of the errors...

undefined reference to `siglongjmp' error when compiling android cocos2dx project for x86 architecture

I am trying to build a cocos2dx project for x86 android architecture but i get the following error when i try to compile it.
./obj/local/x86/curl.a(hostip.o):(.text.alarmfunc+0x21): undefined reference to `siglongjmp'
./obj/local/x86/curl.a(hostip.o): In function `Curl_resolv_timeout':
(.text.Curl_resolv_timeout+0x156): undefined reference to `sigsetjmp'
When i googled the error i found that it has been reported as issue 19851 in google code. They have not made any fixes yet but they had suggested to add a modified libc.so and sched.h file. I tried this and it did not work.
Can anyone tell me how to fix this.
Try adding this code to one of your .c or .cpp modules:
#if __i386 && (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include <setjmp.h>
#ifdef __cplusplus
extern "C" {
void siglongjmp(jmp_buf env, int val);
int sigsetjmp(jmp_buf env, int savemask);
}
#endif
void siglongjmp(jmp_buf env, int val)
{
longjmp(env, val);
}
int sigsetjmp(jmp_buf env, int savemask)
{
return setjmp(env);
}
#endif
Fixed the issue by copying libc.so attached in response to issue 19851 to latest version of ndk. I was using ndkr8 and copying the libc.so file to ndkr8d fixed the issue.
Go to the Android NDK page & follow the download and installation instructions.
https://developer.android.com/tools/sdk/ndk/index.html
I'm on OSX, android-ndk-r10e-darwin-x86_64.bin fixed the error for my setup.

can we have #include a*.cpp into another *.cpp file in a single project in VC++ 6.0

i am doing some example programs in VC++ 6.0 . For some simple and small programs i dont want to create separate project for each of the program . i have 2 files created in a single project and there is no .h file , so i have included .cpp file into another .cpp file .
If i compile its working but if i build the code its giving error . Following is the code :
file1.cpp :
-----------
#include <iostream>
#include "Calculate_Int.cpp"
using namespace std;
int main ()
{
cout << "\n\nFirst file \n" ;
int x= cal_integer();
return 0;
}
Calculate_Int.cpp:
------------------
#include<iostream>
using std::cout;
using std::endl;
int cal_integer(){
cout<< 1+2<<endl;
cout<<1-5<<endl;
cout<<1-2<<endl;
return 0;
}
If i build this Project1.exe following is the error :
Linking...
Calculate_Int.obj : error LNK2005: "int __cdecl cal_integer(void)" (?cal_integer##YAHXZ) already defined in file_1.obj
Debug/Project_1.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
Project_1.exe - 2 error(s), 0 warning(s)
Please let me know what is wrong .
Including a file is the same as copying the contents of that file in the point you are including it. This means that the contents of Calculate_Int.cpp are compiled twice in your project. And this is what the linker error is telling you: it does not know which version to choose.
In order to compile main.cpp you just need to know the signature of the functions you are using there; this is, you just need a declaration, not a definition. So you can replace this line in main.cpp:
#include "Calculate_Int.cpp"
with this:
int cal_integer();
And your project will compile and link just fine. Anyway, the right way would be to create a file Calculate_Int.h with that line and include it anywhere you need it.

Resources