undefined reference to `SDL_main' - windows

I am trying to build a project on windows using MinGW and eclipse.
I'm using the SDL library but when i try to complie it, I get the error
g++ -Wl,-subsystem,windows -oplikoo.exe src\mouse.o src\camera.o src\Timer.o src\Pegs.o src\Graphics.o src\FPS.o src\Ball.o -lmingw32 -lSDLmain -lSDL.dll -lSDL_image -lSDL_mixer
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../libSDLmain.a(SDL_win32_main.o): In function `console_main':
/Users/hercules/trunk/SDL-1.2/./src/main/win32/SDL_win32_main.c:315: undefined reference to `SDL_main'
I understand that main has to have the int main(int argc, char *argv[]) signature, and #include <SDL.h> in that file, but it still does not work.

This just happend to me. When i started to define main with the args parameters:
int main(int argc, char* args[])
the compiler error wen away.

main.cpp was not in src dir, not being compiled

Scanning over your compilation line there, I noticed you are attempting to link against "SDL.dll" directly. That's not what you want. You should be linking against libSDL.la (provided you are actually using mingw).
Also, I'm not sure if this affects anything here, but I've heard that you are "supposed to" link to "SDL" last.

Related

Include error when trying to include <wuapi.h>

Recently I tried to create tool using Windows Update Agent API in C++.
The problem is, even include of the wuapi.h header file causes problems on my machine.
It keeps saying, the header file could not be found.
#include <wuapi.h>
int main(int argc, char **args)
{
return 0;
}
Attempt to compile the simple code ends up predictably:
gcc -o tool.exe file.cpp -pedantic -Wall -Wextra
file.cpp:1:10: fatal error: wuapi.h: No such file or directory
#include <wuapi.h>
^~~~~~~~~
compilation terminated.
I found almost no information related to this issue on the Internet so far. That means I'm not sure what's wrong at all.
I'm using Windows 10.0.18362.592 but more importantly I'm using mingw-w64 8.1.0 as a compiler.
At this point I'm not sure, whether mingw-w64 supports this part of Win32 API. I found no useful information though.

undefined reference to `__isoc99_sscanf#GLIBC_2.7'

Hi am trying to compile a src file by linking an external library.
Getting below error
undefined reference to `__isoc99_sscanf#GLIBC_2.7'
make -f GNUmakefile
g++ -m32 -D_POSIX_PTHREAD_SEMANTICS -g -Wl,--version-script=fix.txt -D_GNU_SOURCE -I../include ConnectionAndAuthExample.cpp -o ../Linux/ConnectionAndAuthExample_32 -L../Linux -lsomelib
../Linux/libsomelib.so: undefined reference to `__isoc99_sscanf#GLIBC_2.7'
Contents of fix.txt are
GLIBC_2.7 {
global: *;
local: *;
};
Similar query was answered below here doesnt help. I want to know if anyone else have encountered similar error and resolved it.
My GCC version
-bash-3.2$ g++ --version
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-50)
Finally the link in the question help with slight modification from other answers. Here is my fix.
I created a new cpp file with below contents
#include <iostream>
#include <stdarg.h>
__asm__(".symver __isoc99_sscanf,__isoc99_sscanf#GLIBC_2.7");
#ifdef __cplusplus
extern "C" {
#endif
int __isoc99_sscanf(const char *a, const char *b, va_list args)
{
int i;
va_list ap;
va_copy(ap,args);
i=sscanf(a,b,ap);
va_end(ap);
return i;
}
#ifdef __cplusplus
}
#endif
Compiled it to get the object file and used it along with fix.txt mentioned in the question.
However, I would like to inform that since my third party library was compiled on an higher version. I am getting ELF file OS ABI invalid when I run my binary.
There solution from some other answer which suggests to use patchelf and modify intert section doesnt help as shared files mostly dont have that section.
I also tried to compile glibc2.7 and build my binary using
-Wl,--dynamic-linker
-Wl,--rpath
flags pointing to glibc2.7 . Still in vain.

Getting Started with C development and GTK+

I'm really a Python developer exclusively, but I'm making my first foray into C programming now, and I'm having a lot of trouble getting started. I can't seem to get the hang of compilation and including libraries. At this point, I'm just identifying the libraries that I need and trying to compile them with a basic "hello, world" app just to make sure that I have my environment setup to do the actual programming.
This is a DBus backend application that will use GIO to connect to DBus.
#include <stdlib.h>
#include <gio/gio.h>
int
main (int argc, char *argv[])
{
printf("hello, world");
return 0;
}
Then, I try to compile:
~$ gcc main.c
main.c:2:21: fatal error: gio/gio.h: No such file or directory
#include <gio/gio.h>
I believe that I've installed the correct packages as indicated here, and gio.h exists at /usr/include/glib-2.0/gio/gio.h.
I found a command online to add a search directory to gcc, but that resulted in other errors:
~$ gcc -I /usr/include/glib-2.0/ main.c
In file included from /usr/include/glib-2.0/glib/galloca.h:34:0,
from /usr/include/glib-2.0/glib.h:32,
from /usr/include/glib-2.0/gobject/gbinding.h:30,
from /usr/include/glib-2.0/glib-object.h:25,
from /usr/include/glib-2.0/gio/gioenums.h:30,
from /usr/include/glib-2.0/gio/giotypes.h:30,
from /usr/include/glib-2.0/gio/gio.h:28,
from main.c:2:
/usr/include/glib-2.0/glib/gtypes.h:34:24: fatal error: glibconfig.h: No such file or directory
#include <glibconfig.h>
^
compilation terminated.
There has to be some relatively simple method for being able to set some options/variables (makefile?) to automatically include the necessary headers. I'm also going to use Eclipse-CDT or Anjuta as an IDE and would appreciate help to fix the import path (or whatever it's called in C).
Any help is greatly appreciated.
Use pkg-config (and make). See exactly this answer to a very similar question. See also this and that answers. Don't forget -Wall -g flags to gcc ..
You don't need an IDE to compile your code (the IDE will just run some gcc commands, so better know how to use them yourself).

CppUTest error with -std=c++11 on g++ 4.7.2

I've been using CppUTest with g++ 4.7.2 for a while now without problems. However, I've just flipped the -std=c++11 option on so I can start using std::unique_ptr and it fails immediately.
Even just compiling the main module:
#include <CppUTest/CommandLineTestRunner.h>
int main(int argc, char ** argv) {
return CommandLineTestRunner::RunAllTests(argc, argv);
}
fails with variations on:
In file included from /usr/include/CppUTest/TestHarness.h:77:0,
from /usr/include/CppUTest/CommandLineTestRunner.h:31,
from tests/testmain.cpp:15:
/usr/include/CppUTest/MemoryLeakWarningPlugin.h:56:53: error: declaration of ‘void* operator new(size_t) throw (std::bad_alloc)’ has a different exception specifier
In file included from /usr/include/c++/4.7/ext/new_allocator.h:34:0,
from /usr/include/c++/4.7/x86_64-linux-gnu/bits/c++allocator.h:34,
from /usr/include/c++/4.7/bits/allocator.h:48,
from /usr/include/c++/4.7/string:43,
from /usr/include/CppUTest/SimpleString.h:136,
from /usr/include/CppUTest/Utest.h:34,
from /usr/include/CppUTest/TestHarness.h:71,
from /usr/include/CppUTest/CommandLineTestRunner.h:31,
from tests/testmain.cpp:15:
/usr/include/c++/4.7/new:93:7: error: from previous declaration ‘void* operator new(std::size_t)’
Removing the -std=c++11 option makes everything work just fine again.
The CppUTest documentation makes some comments about the macros conflicting with overloaded new operators, and suggests #including the standard headers first, but I get this problem without including any headers at all, although it looks like CppUTest/CommandLineTestRunner.h is including <string> itself.
Anyone come across this before or know what the issue is?

mingw32 linker error when including QDebug

I have this minimal example:
QT -= gui
CONFIG += qt console
SOURCES += main.cpp
#include <QDebug>
int main(int argc, char** argv)
{
return 0;
}
which gives this link error when building the project:
c:/qtsdk/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: final link failed: Invalid argument
The link command looks like this:
g++ -Wl -Wl -Wl,-subsystem,console -mthreads -o debug\test.exe debug/main.o -L"c:\QtSDK\Desktop\Qt\4.8.1\mingw\lib" -lQtCored4
My setup:
Windows XP SP3
Qt SDK version 1.2.1 (QtCreator 2.4.1, Qt Desktop version 4.8.1) (fresh install at C:\QtSDK\)
MinGW32 version 4.4.0 (included in Qt SDK at C:\QtSDK\mingw\)
If I remove the #include <QDebug>, it compiles fine. If I include some other Qt header file, like for example QCoreApplication, it compiles fine, too.
EDIT: Here is a very strange minimal example. Consider an empty main function like above. Now if i put these includes, it fails to link:
#include <QWidget>
#include <QVariant>
But if I remove one of them, it links without an error.
What's the problem? Why doesn't mingw tell me what the invalid argument is?
Im wondering is the linker could not find the lQtCored4 lib? Is it actually in the -L directory?

Resources