您的位置:首页 > 运维架构 > Linux

Visual Studio 2015update3编译开发linux程序

2016-11-16 13:22 429 查看

Visual Studio 2015update3编译开发linux程序

Visual Studio 2015update3编译开发linux程序,简单的环境搭建
1. 下载Visual Studio 2015update3并安装
2. 需要安装VC_Linux.exe,即Visual C++ for Linux Development
3. 下载链接: https://visualstudiogallery.msdn.microsoft.com/725025cf-7067-45c2-8d01-1e0fd359ae6e
4. 在不同linux上(kali,contos,redhat,ubuntu已测试)安装上安装openssh-server ssh
5. yum install openssh-server gdb gcc g++或者apt-get install openssh-server gdb gcc g++ ssh
6. 下载安装gdbserver或者在线安装
7. 下载地址:https://pkgs.org/download/gdb-gdbserver
8. 例如centos 7 安装:rpm –i gdb-gdbserver-7.2-90.el6.x86_64.rpm
9. 在vs2015中



10:工具->选项->cross platform->connection manager











表示已经生成成功了。在linux下查看



linux下也有生成,可以进行执行。



最好设置虚拟机为自动获取ip地址,要是觉得固定ip好用的话,有可能会报错,所以备份一个出来就可以了,或者改成nat模式
以下是测试小案例,错误有几处:
>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Application
Type\Linux\1.0\Linux.Common.targets(88,5): error : Could not connect to the remote system. Please verify your connection settings, and that your machine is on the network and reachable.
这是没有连接上主机,,检查虚拟机的ip问题,或者用kali测试下,
kali是有个权限问题的,
测试1:contos中:






fjs用户可以编译通过,






这是为什么呢?



linux下运行程序出现“sh: 1: pause: not found”
一般在windows平台写代码为了在终端看到运行结果,所以加入了system("pause");语句。但是在linux下shell里pause不再是一条命令,因此会出现sh: 1: pause: not found的提示。打开源文件删除system("pause");语句即可。另外在用windows上VS编写的代码,在linux下运行必须先转码才行,否则会出现类似
fcbo.c:456:4: error: stray ‘\320’ in program
fcbo.c:456:4: error: stray ‘\217’ in program
fcbo.c:456:4: error: stray ‘\227’ in program
fcbo.c:456:4: error: stray ‘\2’ in program
的错误或警告。同样,在linux下写好的程序也要在windows下另存为成unicode编码,否则编译可能不通过。
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Application Type\Linux\1.0\Linux.Common.targets(245,5): error : g++ exited with code 1, please see the Output Window - Build output for more details (NOTE: the build output verbosity might need to be changed in Tools Options to see more information in the Output Window).
error : g++ -o exited with code 1
error : g++ exited with code



也是固定ip搞得错,这是设置固定ip之后编译出现的错误。
最根本的原因就是你用的是Redhat版本过低,没有安装某某软件导致成的,win和linux没有互相ping通,或者其他原因,请换其余的系统进行测试吧,一般没有太大的问题。






但是换成固定ip之后测试:



也会报错



但是经过测试,还是没有成功,果断换虚拟机。
然后换成别的系统进行再次编译,源代码如下:



运行后:



在root用户测试:不会报错



出现log问题解决方案



在红帽系统进行测





运行成功,
红帽root用户:






测试动态库

最简单的方法:
首先在vs15中建立项目和之前的一样,新建.h和.c
01.h
#pragma once
void gogo()
{
printf("linux...\n");
}
01. c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "01.h"
int main(int argc, char *argv[])
{
gogo();
printf("test...\n");
gogo();
return 0;
}
直接编译:
error : relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
1> D:\itcast_c++\code\win_linux\01test_dll\01test_dll\obj\x64\Debug\01.o : error : 错误的值
这样怎么解决:-fPIC错误,,就是 gcc -fPIC a.c b.c c.c -c
解决方案



会报错,但是经过测试,动态库可以实现.



Program received signal SIGSEGV, Segmentation fault.
0x0000000000000001 in ?? ()
Segmentation fault
Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
程序“”已退出,返回值为 0 (0x0)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: