首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gcc没有在Visual Studio Code中编译任何其他库

gcc没有在Visual Studio Code中编译任何其他库
EN

Stack Overflow用户
提问于 2021-05-11 01:32:55
回答 1查看 152关注 0票数 1

我在Windows10上,我使用Visual Studio Code作为IDE和代码编辑器来编写一些C代码。我安装了Microsoft的C/C++扩展以及Jun Han的code Runner。我先安装了msys2,然后在里面安装了mingw64。我将/mingw64/bin添加到路径中。

当包含标准库时,代码可以很好地编译,但是添加任何其他库(在我的实例中是GTK)就可以进行编译。下面是我的.vscode文件:

.vscode\c_cpp_Properties.json:

代码语言:javascript
复制
{
  "configurations": [
    {
      "name": "windows-gcc-x64",
      "includePath": [
        "${workspaceFolder}/**",
        "C:/msys64/mingw64/include/**", //added by user
        "C:/msys64/mingw64/lib/**" //added by user
      ],
      "compilerPath": "C:\\msys64\\mingw64\\bin\\gcc.exe",
      "cStandard": "c99",
      "cppStandard": "c++11",
      "intelliSenseMode": "windows-gcc-x64",
      "compilerArgs": [
        "-Wall",
        "-Wextra",
        "-Wpedantic"
      ]
    }
  ],
  "version": 4
}

.vscode\settings.json:

代码语言:javascript
复制
{
  "C_Cpp_Runner.cCompilerPath": "C:\\msys64\\mingw64\\bin\\gcc.exe",
  "C_Cpp_Runner.cppCompilerPath": "C:\\msys64\\mingw64\\bin\\g++.exe",
  "C_Cpp_Runner.debuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
  "C_Cpp_Runner.makePath": "C:\\msys64\\mingw64\\bin\\mingw32-make.exe"
}

.vscode\tasks.json:

代码语言:javascript
复制
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe générer le fichier actif",
            "command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-Wall",
                "-Wextra",
                "-Wpedantic",
                "-IC:\\msys64\\mingw64\\include\\**", //added by user
                "-LC:\\msys64\\mingw64\\lib", //added by user
                "-static" //added by user
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compilateur : C:\\msys64\\mingw64\\bin\\gcc.exe"
        },
        {
            "type": "cppbuild",
            "label": "C/C++: gcc.exe générer le fichier actif",
            "command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-Wall",
                "-Wextra",
                "-Wpedantic",
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "compilateur : C:\\msys64\\mingw64\\bin\\gcc.exe"
        }
    ]
}

错误消息:

代码语言:javascript
复制
C:\msys64\mingw64\bin\gcc.exe -g D:\Lycee\1G7\NSI\C\cc.c -o D:\Lycee\1G7\NSI\C\cc.exe -Wall -Wextra -Wpedantic -IC:\msys64\mingw64\include\** -LC:\msys64\mingw64\lib -static
cc1.exe: error: too many filenames given; type 'cc1.exe --help' for usage

La génération s'est achevée avec une ou plusieurs erreurs.
Échec du lancement du processus de terminal (code de sortie : -1).

文件夹结构:

代码语言:javascript
复制
        Directory : C:\msys64\mingw64
Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        09/05/2021     13:12                bin
d-----        09/05/2021     13:04                etc
d-----        09/05/2021     13:04                include
d-----        09/05/2021     13:12                lib
d-----        09/05/2021     13:02                libexec
d-----        09/05/2021     13:02                share
d-----        09/05/2021     13:01                ssl
d-----        09/05/2021     13:01                var
d-----        09/05/2021     12:52                x86_64-w64-mingw32
代码语言:javascript
复制
    Directory : C:\msys64\mingw64\include\gtk-3.0\gtk


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        09/05/2021     13:02                a11y
d-----        09/05/2021     13:02                deprecated
-a----        23/04/2021     10:43           3570 gtk-a11y.h
-a----        23/04/2021     10:43          12188 gtk-autocleanups.h
-a----        23/04/2021     10:43           9820 gtk.h
-a----        23/04/2021     10:43          10179 gtkaboutdialog.h
-a----        23/04/2021     10:43           8707 gtkaccelgroup.h
-a----        23/04/2021     10:43           4247 gtkaccellabel.h
-a----        23/04/2021     10:43           3992 gtkaccelmap.h
-a----        23/04/2021     10:43           2812 gtkaccessible.h
-a----        23/04/2021     10:43           3730 gtkactionable.h
-a----        23/04/2021     10:43           2913 gtkactionbar.h
-a----        23/04/2021     10:43           5997 gtkadjustment.h
-a----        23/04/2021     10:43           1777 gtkappchooser.h
-a----        23/04/2021     10:43           4470 gtkappchooserbutton.h
-a----        23/04/2021     10:43           3617 gtkappchooserdialog.h
-a----        23/04/2021     10:43           5384 gtkappchooserwidget.h
-a----        23/04/2021     10:43           7330 gtkapplication.h
-a----        23/04/2021     10:43           3525 gtkapplicationwindow.h
-a----        23/04/2021     10:43           3054 gtkaspectframe.h
-a----        23/04/2021     10:43          10946 gtkassistant.h
-a----        23/04/2021     10:43           4946 gtkbbox.h
-a----        23/04/2021     10:43           2651 gtkbin.h
-a----        23/04/2021     10:43           7039 gtkbindings.h
-a----        23/04/2021     10:43           2137 gtkborder.h
-a----        23/04/2021     10:43           5221 gtkbox.h
-a----        23/04/2021     10:43           8159 gtkbuildable.h
-a----        23/04/2021     10:43          10511 gtkbuilder.h
-a----        23/04/2021     10:43           6751 gtkbutton.h
-a----        23/04/2021     10:43           6812 gtkcalendar.h
-a----        23/04/2021     10:43          34828 gtkcellarea.h
-a----        23/04/2021     10:43           3652 gtkcellareabox.h
-a----        23/04/2021     10:43           7354 gtkcellareacontext.h
-a----        23/04/2021     10:43           2757 gtkcelleditable.h
-a----        23/04/2021     10:43           7767 gtkcelllayout.h
-a----        23/04/2021     10:43          17871 gtkcellrenderer.h
-a----        23/04/2021     10:43           3483 gtkcellrendereraccel.h
-a----        23/04/2021     10:43           2550 gtkcellrenderercombo.h
-a----        23/04/2021     10:43           2596 gtkcellrendererpixbuf.h
-a----        23/04/2021     10:43           2918 gtkcellrendererprogress.h
-a----        23/04/2021     10:43           2461 gtkcellrendererspin.h
-a----        23/04/2021     10:43           2744 gtkcellrendererspinner.h
-a----        23/04/2021     10:43           2828 gtkcellrenderertext.h
-a----        23/04/2021     10:43           3652 gtkcellrenderertoggle.h
-a----        23/04/2021     10:43           4960 gtkcellview.h
-a----        23/04/2021     10:43           2963 gtkcheckbutton.h
-a----        23/04/2021     10:43           4152 gtkcheckmenuitem.h
-a----        23/04/2021     10:43          12479 gtkclipboard.h
-a----        23/04/2021     10:43           4612 gtkcolorbutton.h
-a----        23/04/2021     10:43           3353 gtkcolorchooser.h
-a----        23/04/2021     10:43           2627 gtkcolorchooserdialog.h
-a----        23/04/2021     10:43           2762 gtkcolorchooserwidget.h
-a----        23/04/2021     10:43           1762 gtkcolorutils.h
-a----        23/04/2021     10:43           8511 gtkcombobox.h
-a----        23/04/2021     10:43           4419 gtkcomboboxtext.h
-a----        23/04/2021     10:43          11423 gtkcontainer.h
-a----        23/04/2021     10:43           4570 gtkcssprovider.h
-a----        23/04/2021     10:43           3876 gtkcsssection.h
-a----        23/04/2021     10:43           2704 gtkdebug.h
-a----        23/04/2021     10:43           7808 gtkdialog.h
-a----        23/04/2021     10:43           4117 gtkdnd.h
-a----        23/04/2021     10:43           4412 gtkdragdest.h
-a----        23/04/2021     10:43           2779 gtkdragsource.h
-a----        23/04/2021     10:43           2516 gtkdrawingarea.h
-a----        23/04/2021     10:43           4835 gtkeditable.h
-a----        23/04/2021     10:43          18620 gtkentry.h
-a----        23/04/2021     10:43           6320 gtkentrybuffer.h
-a----        23/04/2021     10:43           9523 gtkentrycompletion.h
-a----        23/04/2021     10:43          36978 gtkenums.h
-a----        23/04/2021     10:43           3116 gtkeventbox.h
-a----        23/04/2021     10:43           2772 gtkeventcontroller.h
-a----        23/04/2021     10:43           2860 gtkeventcontrollerkey.h
-a----        23/04/2021     10:43           2241 gtkeventcontrollermotion.h
-a----        23/04/2021     10:43           3758 gtkeventcontrollerscroll.h
-a----        23/04/2021     10:43           4985 gtkexpander.h
-a----        23/04/2021     10:43          13213 gtkfilechooser.h
-a----        23/04/2021     10:43           3944 gtkfilechooserbutton.h
-a----        23/04/2021     10:43           2782 gtkfilechooserdialog.h
-a----        23/04/2021     10:43           2392 gtkfilechoosernative.h
-a----        23/04/2021     10:43           2705 gtkfilechooserwidget.h
-a----        23/04/2021     10:43           4613 gtkfilefilter.h
-a----        23/04/2021     10:43           3141 gtkfixed.h
-a----        23/04/2021     10:43          11754 gtkflowbox.h
-a----        23/04/2021     10:43           4685 gtkfontbutton.h
-a----        23/04/2021     10:43           7387 gtkfontchooser.h
-a----        23/04/2021     10:43           2768 gtkfontchooserdialog.h
-a----        23/04/2021     10:43           2806 gtkfontchooserwidget.h
-a----        23/04/2021     10:43           3641 gtkframe.h
-a----        23/04/2021     10:43           4923 gtkgesture.h
-a----        23/04/2021     10:43           2462 gtkgesturedrag.h
-a----        23/04/2021     10:43           2131 gtkgesturelongpress.h
-a----        23/04/2021     10:43           2461 gtkgesturemultipress.h
-a----        23/04/2021     10:43           2335 gtkgesturepan.h
-a----        23/04/2021     10:43           2180 gtkgesturerotate.h
-a----        23/04/2021     10:43           3071 gtkgesturesingle.h
-a----        23/04/2021     10:43           2453 gtkgesturestylus.h
-a----        23/04/2021     10:43           2286 gtkgestureswipe.h
-a----        23/04/2021     10:43           2126 gtkgesturezoom.h
-a----        23/04/2021     10:43           5489 gtkglarea.h
-a----        23/04/2021     10:43           5828 gtkgrid.h
-a----        23/04/2021     10:43           4130 gtkheaderbar.h
-a----        23/04/2021     10:43          17261 gtkicontheme.h
-a----        23/04/2021     10:43          14988 gtkiconview.h
-a----        23/04/2021     10:43           7733 gtkimage.h
-a----        23/04/2021     10:43           5292 gtkimcontext.h
-a----        23/04/2021     10:43           1243 gtkimcontextinfo.h
-a----        23/04/2021     10:43           2868 gtkimcontextsimple.h
-a----        23/04/2021     10:43           1222 gtkimmodule.h
-a----        23/04/2021     10:43           2883 gtkimmulticontext.h
-a----        23/04/2021     10:43           5298 gtkinfobar.h
-a----        23/04/2021     10:43           2784 gtkinvisible.h
-a----        23/04/2021     10:43           9051 gtklabel.h
-a----        23/04/2021     10:43           4182 gtklayout.h
-a----        23/04/2021     10:43           4740 gtklevelbar.h
-a----        23/04/2021     10:43           3564 gtklinkbutton.h
-a----        23/04/2021     10:43          14290 gtklistbox.h
-a----        23/04/2021     10:43           5881 gtkliststore.h
-a----        23/04/2021     10:43           2579 gtklockbutton.h
-a----        23/04/2021     10:43           7241 gtkmain.h
-a----        23/04/2021     10:43          11177 gtkmenu.h
-a----        23/04/2021     10:43           3272 gtkmenubar.h
-a----        23/04/2021     10:43           4033 gtkmenubutton.h
-a----        23/04/2021     10:43           6679 gtkmenuitem.h
-a----        23/04/2021     10:43           5496 gtkmenushell.h
-a----        23/04/2021     10:43           3484 gtkmenutoolbutton.h
-a----        23/04/2021     10:43           5363 gtkmessagedialog.h
-a----        23/04/2021     10:43           1962 gtkmodelbutton.h
-a----        23/04/2021     10:43           1822 gtkmodules.h
-a----        23/04/2021     10:43           3442 gtkmountoperation.h
-a----        23/04/2021     10:43           2926 gtknativedialog.h
-a----        23/04/2021     10:43          11517 gtknotebook.h
-a----        23/04/2021     10:43           2623 gtkoffscreenwindow.h
-a----        23/04/2021     10:43           2330 gtkorientable.h
-a----        23/04/2021     10:43           3324 gtkoverlay.h
-a----        23/04/2021     10:43           3906 gtkpadcontroller.h
-a----        23/04/2021     10:43           5566 gtkpagesetup.h
-a----        23/04/2021     10:43           4417 gtkpaned.h
-a----        23/04/2021     10:43           5186 gtkpapersize.h
-a----        23/04/2021     10:43           8627 gtkplacessidebar.h
-a----        23/04/2021     10:43           3329 gtkplug.h
-a----        23/04/2021     10:43           4828 gtkpopover.h
-a----        23/04/2021     10:43           2188 gtkpopovermenu.h
-a----        23/04/2021     10:43           2935 gtkprintcontext.h
-a----        23/04/2021     10:43          15897 gtkprintoperation.h
-a----        23/04/2021     10:43           3375 gtkprintoperationpreview.h
-a----        23/04/2021     10:43          16089 gtkprintsettings.h
-a----        23/04/2021     10:43           4347 gtkprogressbar.h
-a----        23/04/2021     10:43           4145 gtkradiobutton.h
-a----        23/04/2021     10:43           4025 gtkradiomenuitem.h
-a----        23/04/2021     10:43           3302 gtkradiotoolbutton.h
-a----        23/04/2021     10:43           7883 gtkrange.h
-a----        23/04/2021     10:43          10056 gtkrecentchooser.h
-a----        23/04/2021     10:43           3082 gtkrecentchooserdialog.h
-a----        23/04/2021     10:43           2924 gtkrecentchoosermenu.h
-a----        23/04/2021     10:43           2760 gtkrecentchooserwidget.h
-a----        23/04/2021     10:43           5531 gtkrecentfilter.h
-a----        23/04/2021     10:43          10122 gtkrecentmanager.h
-a----        23/04/2021     10:43           8237 gtkrender.h
-a----        23/04/2021     10:43           3450 gtkrevealer.h
-a----        23/04/2021     10:43           4914 gtkscale.h
-a----        23/04/2021     10:43           4384 gtkscalebutton.h
-a----        23/04/2021     10:43           3224 gtkscrollable.h
-a----        23/04/2021     10:43           2497 gtkscrollbar.h
-a----        23/04/2021     10:43          10046 gtkscrolledwindow.h
-a----        23/04/2021     10:43           3390 gtksearchbar.h
-a----        23/04/2021     10:43           2735 gtksearchentry.h
-a----        23/04/2021     10:43          12769 gtkselection.h
-a----        23/04/2021     10:43           2578 gtkseparator.h
-a----        23/04/2021     10:43           2762 gtkseparatormenuitem.h
-a----        23/04/2021     10:43           2916 gtkseparatortoolitem.h
-a----        23/04/2021     10:43           6035 gtksettings.h
-a----        23/04/2021     10:43           2462 gtkshortcutlabel.h
-a----        23/04/2021     10:43           1830 gtkshortcutsgroup.h
-a----        23/04/2021     10:43           1896 gtkshortcutssection.h
-a----        23/04/2021     10:43           3404 gtkshortcutsshortcut.h
-a----        23/04/2021     10:43           2128 gtkshortcutswindow.h
-a----        23/04/2021     10:43           1509 gtkshow.h
-a----        23/04/2021     10:43           3177 gtksizegroup.h
-a----        23/04/2021     10:43           2010 gtksizerequest.h
-a----        23/04/2021     10:43           2918 gtksocket.h
-a----        23/04/2021     10:43           7981 gtkspinbutton.h
-a----        23/04/2021     10:43           2473 gtkspinner.h
-a----        23/04/2021     10:43           6580 gtkstack.h
-a----        23/04/2021     10:43           2656 gtkstacksidebar.h
-a----        23/04/2021     10:43           2624 gtkstackswitcher.h
-a----        23/04/2021     10:43           3729 gtkstatusbar.h
-a----        23/04/2021     10:43          36417 gtkstylecontext.h
-a----        23/04/2021     10:43           4796 gtkstyleprovider.h
-a----        23/04/2021     10:43           3304 gtkswitch.h
-a----        23/04/2021     10:43           4289 gtktestutils.h
-a----        23/04/2021     10:43           8312 gtktextattributes.h
-a----        23/04/2021     10:43          21622 gtktextbuffer.h
-a----        23/04/2021     10:43           7623 gtktextbufferrichtext.h
-a----        23/04/2021     10:43           3093 gtktextchild.h
-a----        23/04/2021     10:43           4445 gtktextdisplay.h
-a----        23/04/2021     10:43          16376 gtktextiter.h
-a----        23/04/2021     10:43          20587 gtktextlayout.h
-a----        23/04/2021     10:43           4768 gtktextmark.h
-a----        23/04/2021     10:43           5154 gtktexttag.h
-a----        23/04/2021     10:43           3852 gtktexttagtable.h
-a----        23/04/2021     10:43          22305 gtktextview.h
-a----        23/04/2021     10:43           3881 gtktogglebutton.h
-a----        23/04/2021     10:43           3275 gtktoggletoolbutton.h
-a----        23/04/2021     10:43           5400 gtktoolbar.h
-a----        23/04/2021     10:43           4540 gtktoolbutton.h
-a----        23/04/2021     10:43           6124 gtktoolitem.h
-a----        23/04/2021     10:43           5649 gtktoolitemgroup.h
-a----        23/04/2021     10:43           8012 gtktoolpalette.h
-a----        23/04/2021     10:43           4210 gtktoolshell.h
-a----        23/04/2021     10:43           2899 gtktooltip.h
-a----        23/04/2021     10:43           6130 gtktreednd.h
-a----        23/04/2021     10:43          15729 gtktreemodel.h
-a----        23/04/2021     10:43           7649 gtktreemodelfilter.h
-a----        23/04/2021     10:43           3806 gtktreemodelsort.h
-a----        23/04/2021     10:43           7316 gtktreeselection.h
-a----        23/04/2021     10:43           6316 gtktreesortable.h
-a----        23/04/2021     10:43           6455 gtktreestore.h
-a----        23/04/2021     10:43          28132 gtktreeview.h
-a----        23/04/2021     10:43          13126 gtktreeviewcolumn.h
-a----        23/04/2021     10:43          20740 gtktypebuiltins.h
-a----        23/04/2021     10:43           2544 gtktypes.h
-a----        23/04/2021     10:43           3369 gtkversion.h
-a----        23/04/2021     10:43           3724 gtkviewport.h
-a----        23/04/2021     10:43           2550 gtkvolumebutton.h
-a----        23/04/2021     10:43          67581 gtkwidget.h
-a----        23/04/2021     10:43           8856 gtkwidgetpath.h
-a----        23/04/2021     10:43          21244 gtkwindow.h
-a----        23/04/2021     10:43           3224 gtkwindowgroup.h
-a----        23/04/2021     10:43           1078 gtkx-autocleanups.h
-a----        23/04/2021     10:43           1064 gtkx.h

在过去的两天里,我尝试了很多不同的解决方案,我的想法和网站都用完了。我确定我在什么地方犯了什么愚蠢的错误,但是我找不到在哪里。而且,理想情况下,摆脱不必要的参数会很好(如果我能让它工作的话)。

EN

回答 1

Stack Overflow用户

发布于 2021-05-19 01:26:48

这是我想出来的答案:

tasks.json:

代码语言:javascript
复制
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: gcc.exe générer le fichier actif",
            "command": "gcc -Wall -g ${relativeFile} -o ${fileBasenameNoExtension}.exe  `pkg-config --cflags gtk+-3.0` `pkg-config --libs gtk+-3.0`",
            "options": {
                "cwd": "${workspaceFolder}",
                "shell": {"executable": "bash.exe", "args": ["-c"]},
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler : C:\\msys64\\mingw64\\bin\\gcc.exe"
        },
    ]
}

不过,这可能不是一个好主意,因为它还需要安装bash。这感觉很老套和不合适,但它对我来说很有效。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67475138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档