A and B and Compilation Errors STL- vector

解决编程竞赛中的编译错误
本博客介绍了一名参赛者在准备信息学全国联赛时遇到的问题:如何通过两次编译过程找出并解决两个编译错误。通过输入的错误编号序列,参赛者能够识别出哪些错误已得到修正。

A and B and Compilation Errors

 

 

A和B正在准备即将到来的信息学全国联赛。

 

B非常喜欢写程序。写完程序以后,他必须先编译代码。

 

最初,编译器显示有Ñ个编译错误,其中每一个被表示为一个正整数。经过一番努力,B设法解决一个错误,然后又编译了下,又改正了一个错误。

 

B可以完全肯定,他纠正了两个错误,但他忘记了是哪几个编译错误消失了。 

 

你能帮助B来找出那两个已经被改正的错误么?

Input

输入的第一行包含整数n(3≤n≤10^ 5) - 表示编译错误的初始数量。

 

第二行包含n个空格分隔的整数a1,a2,...,an(1≤ai≤10^9),表示第一次编译的时候出现的n个编译错误的序号。

 

第三行包含n-1个空格分开的整数b1,b2,......,bn-1,表示改正了一个错误以后,第二次编译中显示的错误。保证第三行中的所有数字都是第二行中的所有数字,除了一个被改正了的错误。

 

第四行有n-2空格分开的整数c1, c2,..., cn-2,表示在又改正了一个错误之后,第三次编译显示的错误。保证在第四行的所有数字都是来自第三行的,除了被改正的那个错误。

Output

输出只有两行,第一行输出一个整数,表示第一次被改正的错误的序号,第二行也输出一个整数,表示第二次被改正的错误的序号。题目保证输入数据都是正确的。

Sample Input

输入样例1:

5

1 5 8 123 7

123 7 5 1

5 1 7

 

输入样例2:

6

1 4 3 3 5 7

3 7 5 4 3

4 3 7 5

Sample Output

输出样例1:

8

123

 

输出样例2:

1

3

Hint

注意如果有相同序号的编译错误同时出现,B选手每次最多只能修改一个错误。

#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> v1;
    vector<int> v2;
    vector<int> v3;

    int x;
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        v1.push_back(x);
    }
    sort(v1.begin(),v1.end());

    for(int i=0;i<n-1;i++){
        scanf("%d",&x);
        v2.push_back(x);
    }
    v2.push_back(1000000001);//尽量大,排在最后
    sort(v2.begin(),v2.end());

    for(int i=0;i<n;i++){
        if(v1[i]!=v2[i]){
            cout<<v1[i]<<endl;
            break;
        }
    }

    for(int i=0;i<n-2;i++){
        scanf("%d",&x);
        v3.push_back(x);
    }
    v3.push_back(1000000002);
    sort(v3.begin(),v3.end());

    for(int i=0;i<n-1;i++){
        if(v2[i]!=v3[i]){
            cout<<v2[i]<<endl;
            break;
        }
    }
return 0;
}

 

FAILED: cpp/inspireface/CMakeFiles/InspireFace.dir/c_api/inspireface.cc.o D:\android\Android\Sdk\ndk\25.2.9519653\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android21 --sysroot=D:/android/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DFEATURE_BLOCK_ENABLE_OPENCV -DINFERENCE_WRAPPER_ENABLE_MNN -DISF_BUILD_SHARED_LIBS -DInspireFace_EXPORTS -DSODIUM_STATIC -ID:/insightface-master/insightface-master/cpp-package/inspireface/3rdparty/InspireCV/3rdparty/Eigen-3.4.0-Headers -ID:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/. -ID:/insightface-master/insightface-master/cpp-package/inspireface/3rdparty/MNN/include -ID:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/libsodium-cmake-master/libsodium/src/libsodium/include -ID:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/libcorrect/include -ID:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/include/inspireface -ID:/insightface-master/insightface-master/cpp-package/inspireface/3rdparty/yaml-cpp/include -ID:/insightface-master/insightface-master/cpp-package/inspireface/3rdparty/inspireface-precompile-lite/sqlite -ID:/insightface-master/insightface-master/cpp-package/inspireface/3rdparty/InspireCV/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -g0 -std=c++14 -O3 -O3 -mfpu=neon -O3 -DNDEBUG -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -MD -MT cpp/inspireface/CMakeFiles/InspireFace.dir/c_api/inspireface.cc.o -MF cpp\inspireface\CMakeFiles\InspireFace.dir\c_api\inspireface.cc.o.d -o cpp/inspireface/CMakeFiles/InspireFace.dir/c_api/inspireface.cc.o -c D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/c_api/inspireface.cc clang++: warning: argument unused during compilation: '-mfpu=neon' [-Wunused-command-line-argument] In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/c_api/inspireface.cc:8: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/c_api/inspireface_internal.h:9: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./engine/face_session.h:13: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./track_module/face_track_module.h:9: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./track_module/face_detect/face_detect_adapt.h:10: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./middleware/any_net_adapter.h:15: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./middleware/model_archive/inspire_archive.h:15: D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./track_module/landmark/landmark_param.h:13:15: warning: anonymous non-C-compatible type given name for linkage purposes by typedef declaration; add a tag name here [-Wnon-c-typedef-for-linkage] typedef struct { ^ SemanticIndex D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./track_module/landmark/landmark_param.h:14:31: note: type is not C-compatible due to this default member initializer int32_t left_eye_center = 67; ^~ D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./track_module/landmark/landmark_param.h:23:3: note: type is given name 'SemanticIndex' for linkage purposes by this typedef declaration } SemanticIndex; ^ In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/c_api/inspireface.cc:8: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/c_api/inspireface_internal.h:9: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./engine/face_session.h:13: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./track_module/face_track_module.h:16: D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./track_module/tracker_optional/bytetrack/BYTETracker.h:33:141: warning: implicit conversion from 'long' to 'float' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-const-int-float-conversion] double lapjv(const vector<vector<float> > &cost, vector<int> &rowsol, vector<int> &colsol, bool extend_cost = false, float cost_limit = LONG_MAX, ~ ^~~~~~~~ D:/android/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/windows-x86_64/lib64/clang/14.0.7/include/limits.h:47:19: note: expanded from macro 'LONG_MAX' #define LONG_MAX __LONG_MAX__ ^~~~~~~~~~~~ <built-in>:84:22: note: expanded from here #define __LONG_MAX__ 9223372036854775807L ^~~~~~~~~~~~~~~~~~~~ D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/c_api/inspireface.cc:117:20: error: use of undeclared identifier 'token' result->size = token.size(); ^ D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/c_api/inspireface.cc:118:37: error: use of undeclared identifier 'token' result->data = (uint8_t*)malloc(token.size()); ^ D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/c_api/inspireface.cc:119:26: error: use of undeclared identifier 'token' memcpy(result->data, token.data(), token.size()); ^ D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/c_api/inspireface.cc:119:40: error: use of undeclared identifier 'token' memcpy(result->data, token.data(), token.size()); ^ 2 warnings and 4 errors generated. [545/568] Building CXX object cpp/inspireface/CMakeFiles/InspireFace.dir/track_module/face_track_module.cpp.o clang++: warning: argument unused during compilation: '-mfpu=neon' [-Wunused-command-line-argument] In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/track_module/face_track_module.cpp:6: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/track_module/face_track_module.h:9: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/track_module/face_detect/face_detect_adapt.h:10: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./middleware/any_net_adapter.h:15: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./middleware/model_archive/inspire_archive.h:15: D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./track_module/landmark/landmark_param.h:13:15: warning: anonymous non-C-compatible type given name for linkage purposes by typedef declaration; add a tag name here [-Wnon-c-typedef-for-linkage] typedef struct { ^ SemanticIndex D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./track_module/landmark/landmark_param.h:14:31: note: type is not C-compatible due to this default member initializer int32_t left_eye_center = 67; ^~ D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/./track_module/landmark/landmark_param.h:23:3: note: type is given name 'SemanticIndex' for linkage purposes by this typedef declaration } SemanticIndex; ^ In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/track_module/face_track_module.cpp:6: In file included from D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/track_module/face_track_module.h:16: D:/insightface-master/insightface-master/cpp-package/inspireface/cpp/inspireface/track_module/tracker_optional/bytetrack/BYTETracker.h:33:141: warning: implicit conversion from 'long' to 'float' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-const-int-float-conversion] double lapjv(const vector<vector<float> > &cost, vector<int> &rowsol, vector<int> &colsol, bool extend_cost = false, float cost_limit = LONG_MAX, ~ ^~~~~~~~ D:/android/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/windows-x86_64/lib64/clang/14.0.7/include/limits.h:47:19: note: expanded from macro 'LONG_MAX' #define LONG_MAX __LONG_MAX__ ^~~~~~~~~~~~ <built-in>:84:22: note: expanded from here #define __LONG_MAX__ 9223372036854775807L ^~~~~~~~~~~~~~~~~~~~ 2 warnings generated. [546/568] Building CXX object cpp/inspireface/CMakeFiles/I...track_module/tracker_optional/bytetrack/kalmanFilter.cpp.o clang++: warning: argument unused during compilation: '-mfpu=neon' [-Wunused-command-line-argument] [547/568] Building C object cpp/inspireface/CMakeFiles/Ins...__/3rdparty/inspireface-precompile-lite/sqlite/sqlite3.c.o ninja: build stopped: subcommand failed. Build-AndroidArch : Ninja 编译失败! 所在位置 D:\insightface-master\insightface-master\cpp-package\inspireface\command\build_android.ps1:247 字符: 1 + Build-AndroidArch "arm64-v8a" 21 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Build-AndroidArch
最新发布
08-09
C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino: In function 'void setup()': C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino:16:34: error: no matching function for call to 'arduino::esp32::spi::slave::Slave::begin(spi_host_device_t, const int&)' slave.begin(SPI2_HOST, CS_PIN); // 使用HSPI ^ In file included from C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino:2: d:\Arduino IDE\libraries\libraries\ESP32SPISlave/ESP32SPISlave.h:233:10: note: candidate: 'bool arduino::esp32::spi::slave::Slave::begin(uint8_t)' bool begin(const uint8_t spi_bus = HSPI) ^~~~~ d:\Arduino IDE\libraries\libraries\ESP32SPISlave/ESP32SPISlave.h:233:10: note: candidate expects 1 argument, 2 provided d:\Arduino IDE\libraries\libraries\ESP32SPISlave/ESP32SPISlave.h:250:10: note: candidate: 'bool arduino::esp32::spi::slave::Slave::begin(uint8_t, int, int, int, int)' bool begin(uint8_t spi_bus, int sck, int miso, int mosi, int ss) ^~~~~ d:\Arduino IDE\libraries\libraries\ESP32SPISlave/ESP32SPISlave.h:250:10: note: candidate expects 5 arguments, 2 provided d:\Arduino IDE\libraries\libraries\ESP32SPISlave/ESP32SPISlave.h:266:10: note: candidate: 'bool arduino::esp32::spi::slave::Slave::begin(uint8_t, int, int, int, int, int, int)' bool begin(uint8_t spi_bus, int sck, int ss, int data0, int data1, int data2, int data3) ^~~~~ d:\Arduino IDE\libraries\libraries\ESP32SPISlave/ESP32SPISlave.h:266:10: note: candidate expects 7 arguments, 2 provided d:\Arduino IDE\libraries\libraries\ESP32SPISlave/ESP32SPISlave.h:288:10: note: candidate: 'bool arduino::esp32::spi::slave::Slave::begin(uint8_t, int, int, int, int, int, int, int, int, int, int)' bool begin(uint8_t spi_bus, int sck, int ss, int data0, int data1, int data2, int data3, int data4, int data5, int data6, int data7) ^~~~~ d:\Arduino IDE\libraries\libraries\ESP32SPISlave/ESP32SPISlave.h:288:10: note: candidate expects 11 arguments, 2 provided C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino: In function 'void loop()': C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino:24:15: error: 'using ESP32SPISlave = class arduino::esp32::spi::slave::Slave' {aka 'class arduino::esp32::spi::slave::Slave'} has no member named 'available' if (slave.available()) { ^~~~~~~~~ C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino:25:66: error: no matching function for call to 'arduino::esp32::spi::slave::Slave::wait(uint8_t [261], const uint32_t&)' size_t received_size = slave.wait(spi_buffer, BUFFER_SIZE); ^ In file included from C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino:2: d:\Arduino IDE\libraries\libraries\ESP32SPISlave/ESP32SPISlave.h:399:25: note: candidate: 'std::vector<unsigned int> arduino::esp32::spi::slave::Slave::wait(uint32_t)' std::vector<size_t> wait(uint32_t timeout_ms = 0) ^~~~ d:\Arduino IDE\libraries\libraries\ESP32SPISlave/ESP32SPISlave.h:399:25: note: candidate expects 1 argument, 2 provided C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino:58:47: error: no matching function for call to 'min(int, uint16_t&)' int display_count = min(10, block_size); ^ In file included from c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\algorithm:62, from C:\Users\hdhfg\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\cores\esp32/Arduino.h:172, from C:\Users\hdhfg\AppData\Local\Temp\arduino\sketches\9775FC6C6AD6729580772478E700C403\sketch\sketch_jun28b.ino.cpp:1: c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algo.h:3456:5: note: candidate: 'template<class _Tp, class _Compare> _Tp std::min(std::initializer_list<_Tp>, _Compare)' min(initializer_list<_Tp> __l, _Compare __comp) ^~~ c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algo.h:3456:5: note: template argument deduction/substitution failed: C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino:58:47: note: mismatched types 'std::initializer_list<_Tp>' and 'int' int display_count = min(10, block_size); ^ In file included from c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\algorithm:62, from C:\Users\hdhfg\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\cores\esp32/Arduino.h:172, from C:\Users\hdhfg\AppData\Local\Temp\arduino\sketches\9775FC6C6AD6729580772478E700C403\sketch\sketch_jun28b.ino.cpp:1: c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algo.h:3450:5: note: candidate: 'template<class _Tp> _Tp std::min(std::initializer_list<_Tp>)' min(initializer_list<_Tp> __l) ^~~ c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algo.h:3450:5: note: template argument deduction/substitution failed: C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino:58:47: note: mismatched types 'std::initializer_list<_Tp>' and 'int' int display_count = min(10, block_size); ^ In file included from c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\algorithm:61, from C:\Users\hdhfg\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\cores\esp32/Arduino.h:172, from C:\Users\hdhfg\AppData\Local\Temp\arduino\sketches\9775FC6C6AD6729580772478E700C403\sketch\sketch_jun28b.ino.cpp:1: c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algobase.h:243:5: note: candidate: 'template<class _Tp, class _Compare> const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' min(const _Tp& __a, const _Tp& __b, _Compare __comp) ^~~ c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algobase.h:243:5: note: template argument deduction/substitution failed: C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino:58:47: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'uint16_t' {aka 'short unsigned int'}) int display_count = min(10, block_size); ^ In file included from c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\algorithm:61, from C:\Users\hdhfg\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\cores\esp32/Arduino.h:172, from C:\Users\hdhfg\AppData\Local\Temp\arduino\sketches\9775FC6C6AD6729580772478E700C403\sketch\sketch_jun28b.ino.cpp:1: c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algobase.h:195:5: note: candidate: 'template<class _Tp> const _Tp& std::min(const _Tp&, const _Tp&)' min(const _Tp& __a, const _Tp& __b) ^~~ c:\users\hdhfg\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algobase.h:195:5: note: template argument deduction/substitution failed: C:\Users\hdhfg\AppData\Local\Temp\.arduinoIDE-unsaved2025528-21424-mrpq9p.55lhp\sketch_jun28b\sketch_jun28b.ino:58:47: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'uint16_t' {aka 'short unsigned int'}) int display_count = min(10, block_size); ^ exit status 1 Compilation error: no matching function for call to 'arduino::esp32::spi::slave::Slave::begin(spi_host_device_t, const int&)' 出现问题,如何修改
06-29
<think>嗯,用户遇到了Ubuntu编译过程中因为-Wfatal-errors导致编译终止的问题。首先,我需要回忆一下-Wfatal-errors的作用。这个编译选项的作用是在遇到第一个错误时就停止编译,这样可以防止大量错误信息淹没控制台,但有时候也让人难以调试,特别是当有多个警告被当作错误处理的时候。 用户可能是在编译某个项目时启用了这个选项,或者项目本身的Makefile或构建系统中默认开启了它。解决方案的第一步应该是找到触发该错误的编译选项,并考虑是否真的需要-Wfatal-errors。如果用户只是想快速定位第一个错误,可能不需要调整;但如果需要继续编译看到更多错误,就需要修改编译参数。 接下来,常见的解决方法包括移除-Wfatal-errors选项,或者将它与-Wno-error结合使用,把特定的警告降级为非错误。例如,如果有-Werror将警告视为错误,可以针对某些警告使用-Wno-error=...来忽略。此外,检查构建系统(如CMake或Makefile)中的相关设置也很重要,可能需要修改CMakeLists.txt或Makefile中的编译标志。 用户可能不太清楚如何具体修改这些编译选项,特别是如果项目使用自动化工具的话。所以,分步骤说明如何修改CMake或Makefile会很有帮助。例如,在CMake中,使用add_compile_options命令来移除或调整相关选项。另外,环境变量如CFLAGS和CXXFLAGS也可能影响编译,用户可能需要检查或临时覆盖这些变量。 另外,用户可能遇到依赖库版本不兼容的问题,比如引用的libglib2.0或pango版本不正确,这时候需要确保依赖库的版本符合要求。但根据用户的问题,主要焦点是在-Wfatal-errors上,所以可能依赖问题不是主因,但需要提及作为可能的关联因素。 最后,用户可能需要具体的命令示例,比如如何安装特定版本的库,或者如何临时在命令行中传递编译选项。例如,使用make时加上CXXFLAGS="-Wno-error -Wno-fatal-errors"这样的参数。同时,提醒用户在修改构建系统文件前备份,避免引入其他问题。 总结下来,回答的结构应该是先解释-Wfatal-errors的作用,然后逐步提供解决方法,包括修改编译选项、调整构建配置、处理依赖库版本,以及临时环境变量的使用。同时,结合用户提供的引用中的安装命令,可能需要检查相关依赖是否安装正确,但主要关注点还是在编译选项的调整上。</think>关于Ubuntu编译过程中遇到`-Wfatal-errors`导致终止的问题,以下是分步解决方案: ### 1. 理解`-Wfatal-errors`的作用 该编译选项会在遇到第一个错误时立即停止编译,阻止生成后续错误信息,常用于快速定位首要错误。但会中断编译过程,需根据场景调整使用。 ### 2. 修改编译选项 #### 方法1:直接移除该选项 在Makefile/CMakeLists.txt中删除`-Wfatal-errors`标志: ```cmake # CMake示例 add_compile_options(-Wall -Wextra) # 移除此处的-Wfatal-errors ``` #### 方法2:降低警告等级 若需保留警告但避免终止,可组合使用: ```bash # 编译时添加参数 gcc -Wno-error -Wno-fatal-errors your_source.c ``` ### 3. 处理构建系统配置 对于CMake项目,通过临时覆盖编译标志: ```bash cmake -DCMAKE_CXX_FLAGS="-Wno-error -Wno-fatal-errors" .. ``` ### 4. 检查依赖库版本 若因依赖库不兼容触发错误(如引用中提到的libglib/pango版本问题),需固定版本: ```bash # 示例:安装指定版本的glib库[^2] sudo apt-get install libglib2.0-0=2.40.0-2 ``` ### 5. 环境变量覆盖 临时设置环境变量传递编译参数: ```bash CFLAGS="-Wno-error" CXXFLAGS="-Wno-error" make ``` ### 6. 代码层修复 若由代码警告升级为错误导致终止,需修复代码: ```c // 示例:修复未使用变量警告 int main() { int used_var = 42; // 实际使用该变量 printf("%d", used_var); return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值