Linker error _SDL_main unresolved in _main_getcmdline [duplicate] - c++

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 4 years ago.
I'm following LazyFoo's tutorial for SDL2. I went through the first ten lessons, and now i'm getting this error (until i compile i don't get any errors from VS).
1>------ Inizio compilazione: Progetto: yetANewSDLProj, Configurazione: Debug Win32 ------
1>SDL2main.lib(SDL_windows_main.obj) : error LNK2019: riferimento al simbolo esterno _SDL_main non risolto nella funzione _main_getcmdline
1>Compilazione progetto "yetANewSDLProj.vcxproj" NON COMPLETATA.
========== Compilazione: 0 completate, 1 non riuscite, 0 aggiornate, 0 ignorate ==========
"Reference to external symbol "_SDL_main" unresolved in the function "_SDL_getcmdline"
It seems to me that the error is not in my code but rather between SDL's files but i can't figure out which file supposedly Visual Studio doesn't find or why.
I created a new empty project, the only code i have (one file, main.cpp) is:
#include <SDL.h>
#include <SDL_image.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cmath>
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_VIDEO);
while(1){}
SDL_Quit();
return 0;
}
The include files are in the path: "C:\vs_dev_lib\include"
The DLL/lib files: "C:\vs_dev_lib\lib\x86"
Both paths are inserted in "VC++ Directories" (Include Directories / Library Directories).
I also copied all DLLs in both System32 and SysWOW64.
I also tried copying DLLs and .lib file in my project directory.
The headers, dll and lib files are from SDL2, SDL2 image, Mixer and TTF (in all cases development libraries for windows (Visual C++ 32/64-bit).
Linker/Input/Additional Denpendencies look like this:
SDL2.lib
SDL2main.lib
SDL2_image.lib
SDL2_ttf.lib
SDL2_mixer.lib
Linker/System/Subsystem is set to "Console(/SUBSYSTEM:CONSOLE)"
Character set is "Multibyte character set" (translated, not sure how exactly it's spelled in english).
Thanks in advance, if you need any other info let me know.
Googling didn't bring me any luck, i've been stuck with this for the past two days :/

Try defining #define SDL_MAIN_HANDLED prior to including sdl headers if you are going to manually provide an entry point.
#define SDL_MAIN_HANDLED
#include "SDL.h"
int main(int argc, char *argv[])
{
SDL_SetMainReady();
SDL_Init(SDL_INIT_VIDEO);
...

Related

Qr read and generation under QT creator using leadtools

I want to buy license for QR codes read and generating from Leadtools but first I want to try their demo tools. I'm using MSVC 2013 x64 compiler. I think I did everything as follows in documentation:
Copied all dll's to my project directory (where build and release folder are located)
Copied Include and Lib folders to my project directory and add this lines to .pro file.
LIBS += -L$$PWD/Lib/CDLLVC12/x64/ -lLtkrn_x
INCLUDEPATH += $$PWD/Include
PRE_TARGETDEPS += $$PWD/Bin/CDLLVC12/x64/Ltkrnx.dll
include and #define LTV19_CONFIG, here is my code:
#define LTV19_CONFIG
#include <iostream>
#include <Ltkrn.h>
#include <ClassLib/LtWrappr.h>
using namespace std;
int main( ){
if( LT_KRN == LBase::LoadLibraries( LT_KRN, LT_DLGKRN))
cout << "success" << endl;
L_TCHAR licenseFile[] = L"d:\\temp\\TestLic.lic";
L_TCHAR key[] = L"xyz123abc";
LSettings::SetLicenseFile( licenseFile, key);
return 0;
}
Ask leadtools support, but they don't have much experience with working with QT...
When I tries to build application I get following errors:
LNK2019: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl LBase::LoadLibraries(unsigned int,unsigned int)" (__imp_?LoadLibraries#LBase##SAIII#Z) referenced in function main
LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl LSettings::SetLicenseFile(wchar_t *,wchar_t *)" (__imp_?SetLicenseFile#LSettings##SAHPEA_W0#Z) referenced in function main
For following methods documentation says that I only need one dll/lib package (ltkrn). How to fix it? Still I don't get differences between static and dynamic linkage and this could be the problem.
If your linker accepted the 64-bit Ltkrn_x.lib, this suggests the problem is related to how you're using LEADTOOLS and not to QT. That's why I'm posting this as suggested reply instead of a note.
When programming using LEADTOOLS with C++, you normally use one of 2 sets of headers and LIBs:
Either include L_Bitmap.H (or a bunch of headers that includes LtKrn.H) and use the Ltkrn_x, Ltfil_x, etc. set of LIB files.
Or include ClassLib\LtWrappr.h and use only one LIB file, which in your case is Ltwvc_x.lib
Although in both cases you would be using many of the same DLL files such as Ltfilx.dll and Ltkrnx.dll, the reason you don't need their LIB files when using LtWrapper is that the ClassLibrary performs late (on demand) loading of these DLLs at run-time instead of referencing their LIB files at link time.
That's also why you need to call LBase::LoadLibraries() and specify the DLLs you need before your code uses these DLLs.
So to summarize, please try this:
Remove #include "Ltkrn.h"
Remove the linker reference to Ltkrn_x.lib (although you'll need the DLL)
Keep #include "ClassLib/LtWrappr.h"
Add a linker reference to Ltwvc_x.lib

OPENCV linking Error - Win32 & VS2012

i have build openCV 3.0.0 both alpha & beta versions. but everytime i run my project i get this Error only for "imread" function:
error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class cv::String const &,int)" (?imread#cv##YA?AVMat#1#ABVString#1#H#Z) referenced in function _main ...
Here's my code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdlib.h>
#include <stdio.h>
using namespace cv;
int main()
{
Mat a=Mat::zeros(10,10,0);
Mat b;
b=imread("Mu.jpg");
imshow("s",a);
waitKey(1000);
}
when i remove the "imread" function it works fine. builds and runs with no errors and displays the little black image (from "A" Matrix)
I have Re-Build the solutions & OpenCV from scratch and still getting this error.
I'm working with VS2012 and i have added the include & lib paths in a property sheet for the project.
Can anyone help with this?
imread function has been moved to imgcodecs library so you have to include it :
For MSVC users : add "opencv_imgcodecs300d.lib" to "configuration properties-> Linker->Input->Aditional Dependencies" and include "#include "
For Qt users : For Qt IDE users add -lopencv_imgcodecs300d or -lopencv_imgcodecs300 to your .pro file
and #include <opencv2/imgcodecs/imgcodecs.hpp> to your main file
note: the number 300 in the lib name should be changed to match OpenCV version used.
This unresolved external symbol linker errors basically arrives when the compiler is not able to get the definition of that function which is declared.
So make sure you have defined imread("Mu.jpg"){} somewhere in your code and then try compiling the same.
Check whether you have linked the libraries properly and also link may be useful if you are using opencv2.2.

How to fix the fatal error LNK1112 and LNK1120 in VS 2010

I start using OpenCV 2.3 in VS 2010 so there are a lot of things I don't know.
I installed OpenCV by following the guide here: http://siddhantahuja.wordpress.com/2011/07/18/getting-started-with-opencv-2-3-in-microsoft-visual-studio-2010-in-windows-7-64-bit/
but I couldn't chose "Create new project platforms" in step 4 to create a project.
And when I inserted the code, I had many problems.
1>opencv_highgui230d.lib(opencv_highgui230d.dll) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
If I erase waitKey(), I'll have that error:
1>C:\Users\Gia Linh\Documents\Visual Studio 2010\Projects\Testopencv\Debug\Testopencv.exe : fatal error LNK1120: 6 unresolved externals
I don't know how to fix it. Please, help me. Thank you a lot!
#include "stdafx.h"
#include<stdio.h>
#include "cv.h"
#include "highgui.h"
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
char* imagename = "lena.jpg";
Mat img = imread(imagename);
if(img.empty()){
fprintf(stderr,"can't load image %s\n",imagename);
return -1;
}
if(!img.data)
return -1;
namedWindow("show an image",CV_WINDOW_AUTOSIZE);
imshow("show an img",img);
waitKey();
return 0;
}
It seems that you linked to x64 dll's and lib's of opencv and trying to run it under x86 configuration of Visual Studio!
Try adding another path to the environment variables to "opencvDIR/build/x86/vc10/bin" and check all the paths in:
(Im assuming you are trying to run an x86 project)
Project properties > Configuration Properties >Linker > General> Additional Library Directories:
should be something like: opencvDIR\build\x86\vc10\lib.
and
Project properties > Configuration Properties >Linker > Input> Additional Dependencies:
should contain the appropriate lib file name, if you are in debug mode they should be with a "d" at the end of the file name(stands for debug) and without it if you are in release mode.
I would allso suggest creating a property sheet for opencv rather then linking in the project settings!

CGAL unresolved externals when compiling/linking on Windows

I'm getting strange (for me) errors during compiling a test program which uses some parts of the CGAL library.
First, the environment:
Windows 7 64 bits
Boost 1.53
CGAL 4.3
Qt 4.8.4
CMake 2.8.10.2
Visual Studio 2010 professional
I installed all the libraries for 32 bits (if this was an option during installation).
Installation wrong?
In order to install CGAL on my computer, I followed this tutorial: http://www.cgal.org/windows_installation.html. I have to note here that this did not work out-of-the-box for me. During the configuration phase of CGAL in CMake, the boost libraries were not found (although I set the corresponding environment variables, as stated in the tutorial). After setting the incorrect variables in CMake, I was able to complete the configuration and generation phase. After that, I was able to compile both the Debug as well as the Release configurations of CGAL in Visual Studio.
In order to test whether the CGAL lib was installed successfully, I tried to compile and run both the examples and demos. These also did not work immediately. The problem was that the CGAL and Boost headers (and binaries) were not found. After setting the right paths in Project properties => Configuration properties => C/C++ => Additional Include Directories and in Project properties => Configuration properties => Linker => Additional Library Directories the examples and demos could be build. I successfully ran these examples after that.
Actual problem
Now, I'm tyring to compile a simple program, in order to be able to make a certain exercise (http://acg.cs.tau.ac.il/courses/algorithmic-robotics/spring-2013/exercises/assignment-2 exercise 2.1). Here, there are two files supplied: basic_typdef.h and cgal_bootcamp.cpp
*basic_typedef.h*
#pragma once
#include <CGAL/Cartesian.h>
#include <CGAL/Gmpq.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Boolean_set_operations_2/Gps_default_dcel.h>
#include <CGAL/Polygon_set_2.h>
#include <list>
/*******************************************************************************************
* This file contatins basic typedefs (from CGAL and more).
*******************************************************************************************/
typedef CGAL::Gmpq Number_type;
typedef CGAL::Cartesian<Number_type> Kernel;
typedef Kernel::Point_2 Point;
typedef CGAL::Polygon_2<Kernel> Polygon;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes;
typedef CGAL::Polygon_set_2<Kernel> Polygon_set;
typedef std::list<Polygon_with_holes> Polygon_with_holes_container;
*cgal_bootcamp.cpp*
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
return 0;
}
(For convenience I removed the comments in the file cgal_bootcamp.cpp)
With Visual Studio, I can compile the two files as above. However, when I try to create a Point (as defined in basic_typedef.h), I'm getting the (strange) errors:
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
/*
1. Point
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Kernel_23_ref/Class_Point_2.html
*/
// Create Point with the coordinates (0.5, 0.6)
Point p;
return 0;
}
The errors that occur:
Error 1 error LNK2019: unresolved external symbol __imp____gmpq_init referenced in function "public: __thiscall CGAL::Gmpq_rep::Gmpq_rep(void)" (??0Gmpq_rep#CGAL##QAE#XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 2 error LNK2019: unresolved external symbol __imp____gmpq_clear referenced in function "public: __thiscall CGAL::Gmpq_rep::~Gmpq_rep(void)" (??1Gmpq_rep#CGAL##QAE#XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 3 error LNK1120: 2 unresolved externals C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\Debug\warmup-exercise.exe 1 1 warmup-exercise
4 IntelliSense: #error directive: "Mixing a dll CGAL library with a static runtime is a really bad idea..." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 364 4
5 IntelliSense: #error directive: "some required macros where not defined (internal logic error)." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 397 4
I have no clue what is going wrong here (I have to note that I'm still a noob with C++). It seems that there is something wrong with the GMP library (at least the linking to this?) I found in another post that for someone there were no libgmp files build (can't find that post anymore), but that is not the case for me (I think): in CGAL-4.3/auxiliary/gmp/lib I see four files, libgmp-10.dll libgmp-10.lib libmpfr-4.dll and libmpfr-4.lib.
Also the error on line 4 points to something that might cause this error ("Mixing a dll CGAL library with a static runtime is a really bad idea..."), but I do not know what this actually means (or how I can resolve it).
Further, I tried to setup all the libraries on another computer, but I got the same errors there also.
Could anyone point me in the right direction to solve this problem? If you need more information, please let me know.
This comment answered the question: the script cgal_create_cmake_script can be used to create a CMake file that can be used to generate a correct Visual Studio project using CGAL.

linking vs 2012 c++ GDAL

I created a standard windows application with VS 2012 Pro. Just a main.cpp that looks like this:
#include "gdal_priv.h"
#include "cpl_conv.h"
int main(int argc, char* argv[])
{
GDALAllRegister();
return 0;
}
I have set my include path properly. I have gdal_i.lib in my Linker -> Input -> Additional Dependencies.
Link fails with the following message:
1>main.obj : error LNK2019: unresolved external symbol
_GDALAllRegister#0 referenced in function _main
(A scad of other symbols are missing as well, but this one should be easy.)
I used dumpbin and GDALAllRegister appears in the exported symbols. It does appear as "GDALAllRegister", not as "_GDALAllRegister#0".
I tried downloading and using the dev build, and also built myself. Same results.
I just know this is something simple, but I'm totally brain-cramping here. What have I done wrong?
Thanks.
-reilly.
I said it was simple and stupid, and it was.
I had the build manager set to build 32 bit.
Another 4 hours of my life I'll never get back.
Thanks to Manuell for his suggestion. It got me looking in a different direction and I found it.
Sorry, community. This is what comes from programming tired.
-reilly.
This kind of error is typical of a "Calling Convention" mismatch between EXE and LIB.
Check you have __cdecl (/Gd) in "Configuration Properties" -> C++ -> Advanced -> "Calling Convention"