<small id='xdehd'></small><noframes id='xdehd'>

<legend id='xdehd'><style id='xdehd'><dir id='xdehd'><q id='xdehd'></q></dir></style></legend>

    <i id='xdehd'><tr id='xdehd'><dt id='xdehd'><q id='xdehd'><span id='xdehd'><b id='xdehd'><form id='xdehd'><ins id='xdehd'></ins><ul id='xdehd'></ul><sub id='xdehd'></sub></form><legend id='xdehd'></legend><bdo id='xdehd'><pre id='xdehd'><center id='xdehd'></center></pre></bdo></b><th id='xdehd'></th></span></q></dt></tr></i><div id='xdehd'><tfoot id='xdehd'></tfoot><dl id='xdehd'><fieldset id='xdehd'></fieldset></dl></div>
  • <tfoot id='xdehd'></tfoot>
        • <bdo id='xdehd'></bdo><ul id='xdehd'></ul>

      1. 如何在 Visual Studio Code 中包含编译器标志?

        时间:2023-08-03
            <bdo id='Sf6vv'></bdo><ul id='Sf6vv'></ul>
              <tfoot id='Sf6vv'></tfoot>
                <tbody id='Sf6vv'></tbody>
              <i id='Sf6vv'><tr id='Sf6vv'><dt id='Sf6vv'><q id='Sf6vv'><span id='Sf6vv'><b id='Sf6vv'><form id='Sf6vv'><ins id='Sf6vv'></ins><ul id='Sf6vv'></ul><sub id='Sf6vv'></sub></form><legend id='Sf6vv'></legend><bdo id='Sf6vv'><pre id='Sf6vv'><center id='Sf6vv'></center></pre></bdo></b><th id='Sf6vv'></th></span></q></dt></tr></i><div id='Sf6vv'><tfoot id='Sf6vv'></tfoot><dl id='Sf6vv'><fieldset id='Sf6vv'></fieldset></dl></div>

                • <legend id='Sf6vv'><style id='Sf6vv'><dir id='Sf6vv'><q id='Sf6vv'></q></dir></style></legend>

                • <small id='Sf6vv'></small><noframes id='Sf6vv'>

                  本文介绍了如何在 Visual Studio Code 中包含编译器标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个程序,我试图在使用 fftw 函数的 Visual Studio Code 调试器中运行该程序.它用命令编译

                  I have a program that I am trying to run in the Visual Studio Code debugger that uses fftw functions. It compiles with the command

                  g++ dimer.cpp -std=c++11 -lfftw3 
                  

                  在我电脑上的终端上,没有抱怨未定义的引用.但是,在生成 launch.json 文件后,我的程序会抱怨 fftw 库函数和 -std=c++14 编译器标志.

                  on the terminal on my computer without complaining about undefined references. However, after generating a launch.json file, my program complains about fftw library functions and about the -std=c++14 compiler flag.

                  我相信它只需要 -std=c++11-lfftw3 的额外标志使 Visual Studio Code 中的调试器正常工作.我正在使用 Microsoft 的 C/C++ 扩展和 Code Runner 扩展.

                  I believe that it needs just the extra flags of -std=c++11 and -lfftw3 for the debugger in Visual Studio Code to work. I am using Microsoft's C/C++ extension and the Code Runner extension.

                  我正在尝试将 Mathematica 代码文档转换为 C++.

                  I am trying to transform a Mathematica document of code into c++.

                  以下是我从输出中得到的错误.

                  Below are the errors I get from the output.

                  Executing task: /usr/bin/g++ -g /home/msammartino/Documents/twochain/dimer.cpp -o /home/msammartino/Documents/twochain/dimer <
                  
                  In file included from /usr/include/armadillo:54:0,
                               from /home/msammartino/Documents/twochain/dimer.cpp:6:
                  /usr/include/armadillo_bits/compiler_setup.hpp:530:108: note: #pragma message: NOTE: suggest to enable C++14 mode for faster code; add -std=c++14 to compiler flags
                   #pragma message ("NOTE: suggest to enable C++14 mode for faster code; add -std=c++14 to compiler flags")
                                                                                                                          ^
                  /tmp/ccgb7Xsv.o: In function `r2r_dsine_fftw_forward_dimer(int, double*, double*, Eigen::Matrix<double, 2, 2, 0, 2, 2> (&) [2048], Eigen::Matrix<double, 2, 2, 0, 2, 2> (&) [2048])':
                  /home/msammartino/Documents/twochain/dimer.cpp:99: undefined reference to `fftw_plan_r2r_1d'
                  /home/msammartino/Documents/twochain/dimer.cpp:100: undefined reference to `fftw_plan_r2r_1d'
                  /home/msammartino/Documents/twochain/dimer.cpp:101: undefined reference to `fftw_plan_r2r_1d'
                  /home/msammartino/Documents/twochain/dimer.cpp:102: undefined reference to `fftw_plan_r2r_1d'
                  /home/msammartino/Documents/twochain/dimer.cpp:103: undefined reference to `fftw_execute'
                  /home/msammartino/Documents/twochain/dimer.cpp:104: undefined reference to `fftw_execute'
                  /home/msammartino/Documents/twochain/dimer.cpp:105: undefined reference to `fftw_execute'
                  /home/msammartino/Documents/twochain/dimer.cpp:106: undefined reference to `fftw_execute'
                  /tmp/ccgb7Xsv.o: In function `r2r_dsine_fftw_backward_dimer(int, double*, double*, Eigen::Matrix<double, 2, 2, 0, 2, 2> (&) [2048], Eigen::Matrix<double, 2, 2, 0, 2, 2> (&) [2048])':
                  /home/msammartino/Documents/twochain/dimer.cpp:166: undefined reference to `fftw_plan_r2r_1d'
                  /home/msammartino/Documents/twochain/dimer.cpp:167: undefined reference to `fftw_plan_r2r_1d'
                  /home/msammartino/Documents/twochain/dimer.cpp:168: undefined reference to `fftw_plan_r2r_1d'
                  /home/msammartino/Documents/twochain/dimer.cpp:169: undefined reference to `fftw_plan_r2r_1d'
                  /home/msammartino/Documents/twochain/dimer.cpp:170: undefined reference to `fftw_execute'
                  /home/msammartino/Documents/twochain/dimer.cpp:171: undefined reference to `fftw_execute'
                  /home/msammartino/Documents/twochain/dimer.cpp:172: undefined reference to `fftw_execute'
                  /home/msammartino/Documents/twochain/dimer.cpp:173: undefined reference to `fftw_execute'
                  collect2: error: ld returned 1 exit status
                  The terminal process terminated with exit code: 1
                  
                  Terminal will be reused by tasks, press any key to close it.
                  

                  如果我提出这个问题的方式有任何问题,请告诉我.

                  Please let me know about any problems with the way I have asked this question.

                  推荐答案

                  简单的选择是 在 tasks.json 配置中将它们作为 args 传递:

                  The easy option is to pass them as args in your tasks.json configuration:

                  {
                    "version": "2.0.0",
                    "tasks": [
                      {
                        "label": "build-all",
                        "type": "shell",
                        "args": [
                            "-std=c++11",
                            "-lfftw3",
                            "-L",
                            "/path/to/libs",
                            "/path/to/file.cpp"
                        ],
                        "command": "g++",
                      }
                    ]
                  }
                  

                  更易于维护和共享的选项是创建一个 Makefile 并将它们全部设置在那里:

                  The more maintainable, shareable option is to create a Makefile and set them all there:

                  # Specify compiler to be used
                  CXX = g++
                  CXXFLAGS += -g -std=c++11 -fPIC -march=x86-64
                  
                  # Specify paths to headers
                  INCLUDES += -I include
                  
                  # Specify paths to the libraries
                  LDFLAGS  += -L /path/to/libs
                  
                  # Specify the link libraries
                  LLIBS    += -lfftw3
                  
                  # ... add other configs ...
                  
                  $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(OBJ_DIR)
                      $(CXX) -c $(CXXFLAGS) $(INCLUDES) $< -o $@
                  
                  $(OBJ_DIR)/$(PROGRAM): $(OBJS)
                      $(CXX) $(LDFLAGS) $^ $(LLIBS) -o $@
                  

                  然后在您的任务配置中,只需调用make:

                  Then in your task configuration, just call make:

                  {
                    "version": "2.0.0",
                    "tasks": [
                      {
                        "label": "build-all",
                        "type": "shell",
                        "options": {
                            "cwd": "${workspaceFolder}",
                            "env": {
                              ...
                            }
                        },
                        "command": "make -f Makefile.x86_64",
                      }
                    ]
                  }
                  

                  如果你有依赖于 env 的路径,你可以在你的 Makefile 中指定一个变量(例如 MY_LIBS),然后在任务配置的 env 块中设置它们(例如,MY_LIBS":/path/to/libs").

                  If you have env-dependent paths, you can specify a variable in your Makefile (ex. MY_LIBS) and then set them in the env block of the task configuration (ex. "MY_LIBS": "/path/to/libs").

                  Makefile 选项的优点在于:

                  The advantage of the Makefile option is that:

                  • 不使用 VS Code 的人仍然可以编译您的代码(从控制台或其他 IDE).
                  • 如果您使用的是 CI/CD 管道,则不需要单独的配置.您可以使用相同的 Makefile 使用 VS Code 在本地进行构建,也可以使用 CI/CD 进行构建.
                  • 您可以将 Makefile 提交到存储库,然后只需在本地 tasks.json 配置中使用环境变量来指定特定于环境的设置.

                  这篇关于如何在 Visual Studio Code 中包含编译器标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 VSCode C++ 扩展中启用 C++17 支持 下一篇:Visual Studio Code:从用户获取输入

                  相关文章

                  最新文章

                • <legend id='EzMed'><style id='EzMed'><dir id='EzMed'><q id='EzMed'></q></dir></style></legend>
                    1. <i id='EzMed'><tr id='EzMed'><dt id='EzMed'><q id='EzMed'><span id='EzMed'><b id='EzMed'><form id='EzMed'><ins id='EzMed'></ins><ul id='EzMed'></ul><sub id='EzMed'></sub></form><legend id='EzMed'></legend><bdo id='EzMed'><pre id='EzMed'><center id='EzMed'></center></pre></bdo></b><th id='EzMed'></th></span></q></dt></tr></i><div id='EzMed'><tfoot id='EzMed'></tfoot><dl id='EzMed'><fieldset id='EzMed'></fieldset></dl></div>

                      <small id='EzMed'></small><noframes id='EzMed'>

                      • <bdo id='EzMed'></bdo><ul id='EzMed'></ul>

                      <tfoot id='EzMed'></tfoot>