0

I'm just doing an exercice on lists of object. I'm a beginner still...

I have 3 files:

-main.cpp //main fonction is in there

-list.cpp

-list.h

Quit sure my code is correct.But when I compile it and run it with g++ (version 6.3.0) in VSCode, I get this error message:

AppData\Local\Temp\cckbchz9.o:main.cpp:(.text$_ZN5ListeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE7insererEiRKS5_[__ZN5ListeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE7insererEiRKS5_]+0x4d):

**undefined reference to `Liste**<std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> > >::CreerNoeud(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
**collect2.exe**: erreur : ld a retourné 1 code d'état d'exécution

So I tried to compile my 3 files to object files with command prompt and then linking/executing the files:

  1. g++ -c liste.cpp liste.h main.cpp
  2. g++ -o liste.o main.o -L libstdc++-6( I updated this because i thought it would resolve the problem)

But I still get the error message.

When i use libstdc++(g++ -o main.o liste.o -L libstdc++) , I get:

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: erreur : ld a retourné 1 code d'état d'exécution

My main fonction is declared : int main(void){//CODE}

So I've been looking on internet for 2H. Please help me ...

This small code reproduce the error(but you need to install raylib)

#include<iostream>
#include "C:/raylib/raylib/src/raylib.h"
using namespace std;


void InitWindow(int width, int height, const char *title);          

int main(void){
    InitWindow(10,10,"fenetre");
    return 0;
}
  • difficult to tell what your problem is without a [mre]. You should never need to explicitly link to `libstdc++` – Alan Birtles Jul 20 '22 at 08:50
  • That should be `g++ -c liste.cpp main.cpp` and `g++ -o my_application_name liste.o main.o`. `-o` takes the executable name as its argument. – molbdnilo Jul 20 '22 at 09:02
  • What is the "my_application_name"? what should I put? No executable has been yet created – simplementdan Jul 20 '22 at 09:07
  • @simplementdan You should put the name you want to give to your program, and don't forget the ".exe" suffix. (Or you could leave `-o` out and most likely get a program called "a.exe".) Your failed attempt tried to create the program "liste.o" by linking just "main.o" and the standard library. – molbdnilo Jul 20 '22 at 10:55
  • g++ -o prog.exe liste.o main.o like this ? – simplementdan Jul 20 '22 at 11:03
  • still didn t resolve my problem.. :/ – simplementdan Jul 21 '22 at 08:07

0 Answers0