New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux下使用QtCreator构建任务问题 #73

Closed
Geequlim opened this Issue Apr 15, 2017 · 7 comments

Comments

Projects
None yet
2 participants
@Geequlim

Geequlim commented Apr 15, 2017

OS: Arch Linux x86_64
XMake Version: v2.1.3.201704160314 installed from AUR
在终端中通过xmake构建项目无问题。
在QtCreator IDE中配置项目如下
2017-04-16 03-25-31
执行构建命令QtCreator抱怨如下

03:27:16: 为项目learning执行步骤 ...
03:27:16: 无法启动进程"/usr/sbin/xmake" 
Error while building/deploying project learning (kit: GCC)
When executing step "自定义进程步骤"
03:27:16: Elapsed time: 00:00.

通过查看/usr/sbin/xmake的内容

#/!bin/bash
export XMAKE_PROGRAM_DIR=/usr/share/xmake
/usr/share/xmake/xmake "$@"

得到启示,修改构建配置为如下所示后可以正常通过IDE构建和清理项目
2017-04-16 03-30-08

想问一下XMAKE_PROGRAM_DIR这个环境变量的值是否可在xmake实现中获取到,然后/usr/sbin/xmake则可以建立文件软链接到/usr/share/xmake/xmake,这样应该可以解决这个问题吧。

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 15, 2017

Member

为什么不直接设置xmake而要写全绝对路径呢?qt不支持? 通过 XMAKE_PROGRAM_DIR 分离

  • 一个原因是暂时没找到方便靠谱的方式在程序中获取自身的绝对路径
  • 还有个原因是,有时候不安装的情况下使用xmake,这个可执行程序和脚本目录 是分离的,这样通过环境变量设置也可以正常运行
Member

waruqi commented Apr 15, 2017

为什么不直接设置xmake而要写全绝对路径呢?qt不支持? 通过 XMAKE_PROGRAM_DIR 分离

  • 一个原因是暂时没找到方便靠谱的方式在程序中获取自身的绝对路径
  • 还有个原因是,有时候不安装的情况下使用xmake,这个可执行程序和脚本目录 是分离的,这样通过环境变量设置也可以正常运行

@waruqi waruqi added the discussion label Apr 15, 2017

@Geequlim

This comment has been minimized.

Show comment
Hide comment
@Geequlim

Geequlim Apr 15, 2017

Geequlim commented Apr 15, 2017

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 15, 2017

Member

这个我之后可以再改进下,在源码编译安装的时候把它写入进去,作为默认路径,这个版本你就先暂时通过环境变量的方式。这么用吧。。

Member

waruqi commented Apr 15, 2017

这个我之后可以再改进下,在源码编译安装的时候把它写入进去,作为默认路径,这个版本你就先暂时通过环境变量的方式。这么用吧。。

@waruqi waruqi added the improvement label Apr 15, 2017

@Geequlim

This comment has been minimized.

Show comment
Hide comment
@Geequlim

Geequlim Apr 15, 2017

@waruqi 非常感谢!

一个原因是暂时没找到方便靠谱的方式在程序中获取自身的绝对路径

针对这个问题可以参考下面的实现方式

/***********************************************************************
* Code listing from "Advanced Linux Programming," by CodeSourcery LLC  *
* Copyright (C) 2001 by New Riders Publishing                          *
* See COPYRIGHT for license information.                               *
***********************************************************************/

#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

/* Finds the path containing the currently-running program executable.
   The path is placed into BUFFER, which is of length LEN.  Returns
   the number of characters in the path, or -1 on error.  */

size_t get_executable_path (char* buffer, size_t len)
{
  char* path_end;
  /* Read the target of /proc/self/exe.  */
  if (readlink ("/proc/self/exe", buffer, len) <= 0)
    return -1;
  /* Find the last occurence of a forward slash, the path separator.  */
  path_end = strrchr (buffer, '/');
  if (path_end == NULL)
    return -1;
  /* Advance to the character past the last slash.  */
  ++path_end;
  /* Obtain the directory containing the program by truncating the
     path after the last slash.  */
  *path_end = '\0';
  /* The length of the path is the number of characters up through the
     last slash.  */
  return (size_t) (path_end - buffer);
}

int main ()
{
  char path[PATH_MAX];
  get_executable_path (path, sizeof (path));
  printf ("this program is in the directory %s\n", path);
  return 0;
}

Geequlim commented Apr 15, 2017

@waruqi 非常感谢!

一个原因是暂时没找到方便靠谱的方式在程序中获取自身的绝对路径

针对这个问题可以参考下面的实现方式

/***********************************************************************
* Code listing from "Advanced Linux Programming," by CodeSourcery LLC  *
* Copyright (C) 2001 by New Riders Publishing                          *
* See COPYRIGHT for license information.                               *
***********************************************************************/

#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

/* Finds the path containing the currently-running program executable.
   The path is placed into BUFFER, which is of length LEN.  Returns
   the number of characters in the path, or -1 on error.  */

size_t get_executable_path (char* buffer, size_t len)
{
  char* path_end;
  /* Read the target of /proc/self/exe.  */
  if (readlink ("/proc/self/exe", buffer, len) <= 0)
    return -1;
  /* Find the last occurence of a forward slash, the path separator.  */
  path_end = strrchr (buffer, '/');
  if (path_end == NULL)
    return -1;
  /* Advance to the character past the last slash.  */
  ++path_end;
  /* Obtain the directory containing the program by truncating the
     path after the last slash.  */
  *path_end = '\0';
  /* The length of the path is the number of characters up through the
     last slash.  */
  return (size_t) (path_end - buffer);
}

int main ()
{
  char path[PATH_MAX];
  get_executable_path (path, sizeof (path));
  printf ("this program is in the directory %s\n", path);
  return 0;
}
@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 15, 2017

Member

谢谢,这种方式只对 linux下有效,没法支持macOS,但我可以在下个版本中,对linux平台先尝试处理下。。

Member

waruqi commented Apr 15, 2017

谢谢,这种方式只对 linux下有效,没法支持macOS,但我可以在下个版本中,对linux平台先尝试处理下。。

@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 15, 2017

Member

http://stackoverflow.com/questions/1528298/get-path-of-executable 这里面看似有个不错的跨平台解决方式,针对不同平台进行处理,但是我觉得还是没法保证完全的跨平台化,因此这个环境变量的设置还是需要的,毕竟这种方式是最稳定有效,也是最便捷的。。

我觉得可以通过如下的方式进行一些改进:

  1. 如果存在XMAKE_PROGRAM_DIR环境变量,优先使用
  2. 如果不存在,尝试针对不同平台的接口,进行路径获取
Member

waruqi commented Apr 15, 2017

http://stackoverflow.com/questions/1528298/get-path-of-executable 这里面看似有个不错的跨平台解决方式,针对不同平台进行处理,但是我觉得还是没法保证完全的跨平台化,因此这个环境变量的设置还是需要的,毕竟这种方式是最稳定有效,也是最便捷的。。

我觉得可以通过如下的方式进行一些改进:

  1. 如果存在XMAKE_PROGRAM_DIR环境变量,优先使用
  2. 如果不存在,尝试针对不同平台的接口,进行路径获取
@waruqi

This comment has been minimized.

Show comment
Hide comment
@waruqi

waruqi Apr 15, 2017

Member

我在dev分支上,已经对其进行改进,在下个版本中,只需要执行:/usr/share/xmake/xmake 就可以正常运行,并且还是可以通过设置XMAKE_PROGRAM_DIR来修改脚本目录,不影响/use/sbin/xmake

Member

waruqi commented Apr 15, 2017

我在dev分支上,已经对其进行改进,在下个版本中,只需要执行:/usr/share/xmake/xmake 就可以正常运行,并且还是可以通过设置XMAKE_PROGRAM_DIR来修改脚本目录,不影响/use/sbin/xmake

@waruqi waruqi closed this Apr 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment