You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code中用g++编译C++代码时出现collect2.exe链接错误求助

C++链接错误求助:undefined reference 及 WinMain@16问题

我是C初学者,正在做对象列表相关练习,现有main.cpp、liste.cpp、liste.h三个文件,自认代码逻辑无问题。但使用g 6.3.0在VS Code中编译运行时,出现以下链接错误:

undefined reference to Liste<std::__cxx11::basic_string<char...>>::CreerNoeud

collect2.exe返回状态码1。

已尝试的操作

  • 手动通过命令行编译链接:
    1. 执行编译命令:g++ -c liste.cpp liste.h main.cpp
    2. 执行链接命令:g++ -o liste.o main.o -L libstdc++-6,错误未解决
  • 更换链接命令为g++ -o main.o liste.o -L libstdc++时,出现新错误:
    undefined reference to WinMain@16
    
    我的main函数声明为int main(void){//CODE}。

已花费2小时上网查找解决方案但无果,特来求助。以下是可复现错误的简化代码(需预先安装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;
}

内容的提问来源于stack exchange,提问作者simplementdan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 08:30:24