C/C++教程

2021-10-31-ubuntu下配vscode c++环境

本文主要是介绍2021-10-31-ubuntu下配vscode c++环境,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

文章目录

  • 一、code利用软连接解决了
  • 二、gcc的ld软连接有问题
    • 1./home/liuzhe/projects/helloworld
    • 2./home/liuzhe/test
  • 三、线索:cmake、colcon

一、code利用软连接解决了

二、gcc的ld软连接有问题

1./home/liuzhe/projects/helloworld

liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ ll
总用量 8
drwxrwxr-x 2 liuzhe liuzhe 4096 10月 31 20:15 ./
drwxrwxr-x 3 liuzhe liuzhe 4096 10月 31 19:46 ../
-rw-rw-r-- 1 liuzhe liuzhe    0 10月 31 20:15 helloworld.cpp
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc helloworld.cpp -o main
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ ldd helloworld.cpp 
        不是动态可执行文件
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc helloworld.cpp 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ g++ helloworld.cpp 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ g++ helloworld.cpp 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ g++ helloworld.cpp 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc helloworld.cpp 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ ll
总用量 8
drwxrwxr-x 2 liuzhe liuzhe 4096 10月 31 20:24 ./
drwxrwxr-x 3 liuzhe liuzhe 4096 10月 31 19:46 ../
-rw-rw-r-- 1 liuzhe liuzhe    0 10月 31 20:15 helloworld.cpp
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc helloworld.cpp 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc helloworld.cpp 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc helloworld.cpp 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc -E test.c -o test.i
gcc: error: test.c: 没有那个文件或目录
gcc: fatal error: no input files
compilation terminated.
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ ll
总用量 8
drwxrwxr-x 2 liuzhe liuzhe 4096 10月 31 20:29 ./
drwxrwxr-x 3 liuzhe liuzhe 4096 10月 31 19:46 ../
-rw-rw-r-- 1 liuzhe liuzhe    0 10月 31 20:15 helloworld.cpp
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc -E test.c -o test.i
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc -S test.i -o test.s
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc -c test.s -o test.o
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc test.o -o test
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc test.o -o test
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ g++ test.c -o main.out
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ g++ test.c -o main.out
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ gcc test.c
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:helloworld$ 

2./home/liuzhe/test

liuzhe@liuzhe-Lenovo-Legion-Y7000:test$ gcc helloworld.cpp 
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o:在函数‘_start’中:
(.text+0x20):对‘main’未定义的引用
collect2: error: ld returned 1 exit status
liuzhe@liuzhe-Lenovo-Legion-Y7000:test$ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

liuzhe@liuzhe-Lenovo-Legion-Y7000:test$ 

三、线索:cmake、colcon

这篇关于2021-10-31-ubuntu下配vscode c++环境的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!