This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 2 years ago.
Unfortunately, I couldn't find any beginner friendly tutorial on how to use giflib.
This is my code:
#include <iostream>
#include <gif_lib.h>
int main(int argc, char** argv)
{
if (argc < 2)
{
std::cerr << "No argument" << std::endl;
return 1;
}
GifFileType *gifFile = DGifOpenFileName(argv[1], NULL);
DGifSlurp(gifFile);
}
I try to compile it like this:
g++ main.cpp
but it yields this error:
/usr/bin/ld: /tmp/ccd5G2QR.o: in function `main':
main.cpp:(.text+0x5c): undefined reference to `DGifOpenFileName'
/usr/bin/ld: main.cpp:(.text+0x6c): undefined reference to `DGifSlurp'
collect2: error: ld returned 1 exit status
I'm on Ubuntu 20.04 and I've installed the libgif-dev package.
How to link the giflib library for the functions to work?
Trying randomly around I found it's:
g++ main.cpp -lgif
Related
This question already has answers here:
C - Undefined Reference to WSAStartup#8'
(5 answers)
Closed 5 months ago.
I'm beginning with socket programming in C++, and as a normal student, I went to search online.
The problem is, it doesn't matter what I do, I always get the following errors:
C:\Users\farin\AppData\Local\Temp\ccQCkFqw.o:main.cpp:(.text+0x37): undefined reference to `WSAStartup#8'
C:\Users\farin\AppData\Local\Temp\ccQCkFqw.o:main.cpp:(.text+0x48): undefined reference to `WSAGetLastError#0'
collect2.exe: error: ld returned 1 exit status
I'm using MinGW in Visual Studio Code.
Here's the sample code I've been messing around with:
/*
Initialise Winsock
*/
#include<stdio.h>
#include<winsock2.h>
#pragma comment(lib,"ws2_32.lib") //Winsock Library
int main(int argc , char *argv[])
{
WSADATA wsa;
printf("\nInitialising Winsock...");
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
{
printf("Failed. Error Code : %d",WSAGetLastError());
return 1;
}
printf("Initialised.");
return 0;
}
I've already tried linking to the compiler, and possibly gone throught all the pages
about the subject that I could find.
Solution is here!
Just ran throught the command line, as follow:
g++ main.cpp -o main.exe -lws2_32
Thanks to Retired Ninja.
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
undefined reference to `WinMain#16'
(7 answers)
Closed 2 years ago.
My version of DEV C++ is 5.11 and I have used version SDL2-2.0.12 and OS is Windows 10.
Folder path of sdl.h file is C:\Program Files (x86)\Dev-Cpp\SDL2-2.0.12\x86_64-w64-mingw32\include\SDL2
I have done my project settings as shown in ::
https://thenumbat.github.io/cpp-course/sdl2/01/devSetup.html#:~:text=Open%20up%20your%20project%20and,and%20select%20the%20lib%20folder.
My program
#include <iostream>
#include "SDL.h"
using namespace std;
int main( int argc, char* args[] )
{
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
cout << "SDL init failed.\n";
return 1;
}
SDL_Quit();
return 0;
}
While compiling I am getting such message::
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib\libmingw32.a(lib64_libmingw32_a-crt0_c.o) In function `main':
C:\crossdev\src\mingw-w64-v3-git\mingw-w64-crt\crt\crt0_c.c undefined reference to `WinMain'
------ this is in red color ---------
C:\Program Files (x86)\Dev-Cpp\SDL2-2.0.12\x86_64-w64-mingw32\collect2.exe [Error] ld returned 1 exit status
C:\Program Files (x86)\Dev-Cpp\SDL2-2.0.12\x86_64-w64-mingw32\Makefile.win recipe for target 'SDLproj1.exe' failed
Please see the attached image.
This question already has answers here:
undefined reference to WinMain#16 C++, SDL-2
(2 answers)
undefined reference to `WinMain#16'
(7 answers)
Closed 2 years ago.
I have this snippet of code:
#include <SDL2/SDL.h>
#include <iostream>
int main(int argc, char* argv[]) {
std::cout << "!!!Hello World!!!" << std::endl;
return 0;
}
The error reported is this:
Info: Internal Builder is used for build g++ -o
cavestory-developement.exe "src\cavestory-developement.o" -lmingw32
-lSDL2main -lSDL2 c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0):
undefined reference to `WinMain#16' collect2.exe: error: ld returned 1
exit status
17:13:45 Build Failed. 1 errors, 0 warnings. (took 205ms)
Any help solving this problem would be greatly appreciated.
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
static variable link error [duplicate]
(2 answers)
Closed 3 years ago.
I am not able to use structures for static variable and function. Could anyone explain why exactly is this behavior?
#include <iostream>
using namespace std;
class Foo
{
private:
typedef struct
{
int bee_1;
}bee;
static bee test;
public:
static void Inc(){ test.bee_1++;}
static int getBee_1(){return test.bee_1;}
};
int main(){
Foo::Inc();
Foo::Inc();
Foo::Inc();
Foo::Inc();
cout << Foo::getBee_1();
return 0;
}
I get the following error when I use this code:
clang++-7 -pthread -o main main.cpp
/tmp/main-521333.o: In function `Foo::Inc()':
main.cpp:(.text._ZN3Foo3IncEv[_ZN3Foo3IncEv]+0x24): undefined reference to `Foo::test'
main.cpp:(.text._ZN3Foo3IncEv[_ZN3Foo3IncEv]+0x2e): undefined reference to `Foo::test'
/tmp/main-521333.o: In function `Foo::getBee_1()':
main.cpp:(.text._ZN3Foo8getBee_1Ev[_ZN3Foo8getBee_1Ev]+0x7): undefined reference to `Foo::test'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
compiler exit status 1
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I used the following:
gcc -c -O4 ab_test.c
This worked and generated ab_test.o without error, but
gcc -o ab_test ab_test.o -lgsl -lgslcblas -lm
lead to error as:
**/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib64/crt1.o: In function `_start':
/home/abuild/rpmbuild/BUILD/glibc-2.18/csu/../sysdeps/x86_64/start.S:118: undefined reference to `main'
collect2: error: ld returned 1 exit status**
The code is ab_test.c is as under
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
Main()
{
int i, temp_int;
char amode[30];
char bmode[30];
float wave_vector_y;
for(i=0; i<41; i++)
{
//// set wave vector ////
wave_vector_y = i*0.005;
temp_int = 10000*wave_vector_y;
sprintf(amode,"a%04d.dat",temp_int);
sprintf(bmode,"b%04d.dat",temp_int);
}
}
Your "main" signature should be something like int main(void)or int main(int argc ,char *argv[]) and not old C style syntax for int Main().