标签: makefile

如何编写 Makefile 将脚本复制到服务器

当我在本地机器上编写完脚本后,我需要将它们复制到集群中来执行代码。例如,我想将当前目录中的所有 matlab 文件复制到服务器 id@server 的目录中。

任何人都可以帮助编写一个非常基本的 Makefile 来实现此目的吗?

多谢!

约翰

bash makefile

-1
推荐指数
1
解决办法
3394
查看次数

C Makefile - 缺少分隔符。停止

这是我的 Makefile,我收到错误消息“***missing separator.stop” 我正在尝试编译一个库,但由于某种原因我收到此错误消息。其他类似的 SO 问题表明这是一个制表问题,但我无法解决。

CC=g++
RANLIB=ranlib

LIBSRC=osm.c 
LIBOBJ=$(LIBSRC:.c=.o)

INCS=-I.
CFLAGS = -Wall -g $(INCS)
LOADLIBES = -L./ 

OSMLIB = libosm.a
TARGETS = $(OSMLIB)

TAR=tar
TARFLAGS=-cvf
TARNAME=ex1.tar
TARSRCS=$(LIBSRC) Makefile README

all: $(TARGETS) 

$(TARGETS): $(LIBOBJ)
$(AR) $(ARFLAGS) $@ $^ //this line fails with the warning
$(RANLIB) $@

clean:
$(RM) $(TARGETS) $(OSMLIB) $(OBJ) $(LIBOBJ) *~ *core

depend:
makedepend -- $(CFLAGS) -- $(SRC) $(LIBSRC)

tar:
$(TAR) $(TARFLAGS) $(TARNAME) $(TARSRCS)
Run Code Online (Sandbox Code Playgroud)

c makefile

-1
推荐指数
1
解决办法
1万
查看次数

C 回文程序 - 对 main 的未定义引用

我写了一个函数,它检查字符字符串是否为回文。

//pan.c

#include <stdbool.h>
#include "funs.h"
#include <stdio.h>
#include <string.h>

bool palindrom(char napis[])
{
    int begin, middle, end, length = 0;

    while(napis[length] != '\0')
      length++;

    end = length - 1;
    middle = length;

    for (begin = 0; begin < middle; begin++)
      {
        if(napis[begin] != napis[end])
        {
          return false;
          break;
        }
        end--;
      }
      if(begin == middle)
        return true;
}
Run Code Online (Sandbox Code Playgroud)

我还创建了 funs.h

//funs.h
#include <stdbool.h>
bool palindrom();
Run Code Online (Sandbox Code Playgroud)

现在,我试图在我的主函数中使用这个函数

#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "funs.h"


int main()
{
    char text[100];
    bool …
Run Code Online (Sandbox Code Playgroud)

c linux makefile

-1
推荐指数
1
解决办法
155
查看次数

makefile if/else 中的 Shell 循环语法

我已经循环了,我需要添加到它的if else语句中,如果值== app1print x else print y

我尝试过以下操作,但是当我添加时else出现语法错误,

我究竟做错了什么?

runners:
    @for a in $(apps) ; do
       if (( a ==  "app1"));then
        echo first: $$v ;
       else
        echo second: $$v ;
        fi
     done
Run Code Online (Sandbox Code Playgroud)

linux shell gnu makefile gnu-make

-1
推荐指数
1
解决办法
7111
查看次数

Gnu-Make无法包含makefile

来自文档:

include指令告诉make暂停读取当前的makefile并在继续之前读取一个或多个其他makefile.该指令是makefile中的一行,如下所示:

 include FILENAMES...
Run Code Online (Sandbox Code Playgroud)

FILENAMES可以包含shell文件名模式.




现在,给出一个Makefile:

# we define 'include' from the command-line.
ifdef include


# We create the included Makefile
$(shell echo 'all : ;' >makefile.include)

# And we include it.
# The docs say: "FILENAMES can contain shell file name patterns."
include *.include


else


endif
Run Code Online (Sandbox Code Playgroud)

跑步,我们得到:

$ rm -rf makefile.include && make include=1
makefile:6: *.include: No such file or directory
Run Code Online (Sandbox Code Playgroud)


那么,这里发生了什么?我们显然有:

c shell makefile gnu-make

-2
推荐指数
1
解决办法
669
查看次数

"make"给出了一个可执行文件

我是Makefile的新手.我写了hello.c,当我做"make hello"时,它给出了一个名为"hello"的可执行文件.在内部显示"cc hello.c -o hello".但是没有Makefile怎么制作?如何使可执行文件与源名称相同?

c linux makefile

-2
推荐指数
1
解决办法
57
查看次数

为什么我的makefile调用gcc虽然我设置了CC = g ++?

我有一个g++ -std=c++17 -Wall -Og -g -o main *.cc完美编译的小代码.现在我想要有一个makefile,到目前为止我得到了这个:

CC = g++
CFLAGS = -Wall -std=c++17 -Og -g
DEPS = random_tools.h
OBJ = main.o random_tools.o

%.o: %.c $(DEPS)
    $(CC) $(CFLAGS) -o $@ $<

main: $(OBJ)
    gcc $(CFLAGS) -o $@ $^
Run Code Online (Sandbox Code Playgroud)

然而,当我跑make它崩溃时,告诉我

g++    -c -o main.o main.cc
g++    -c -o random_tools.o random_tools.cc
gcc -Wall -o main main.o random_tools.o
main.o: In function `main':
main.cc:(.text+0x1d): undefined reference to `std::cout'
main.cc:(.text+0x22): undefined reference to `std::ostream::operator<<(int)'
main.cc:(.text+0x27): undefined reference to `std::basic_ostream<char, std::char_traits<char> …
Run Code Online (Sandbox Code Playgroud)

c c++ gcc makefile g++

-2
推荐指数
1
解决办法
903
查看次数

g ++编译器"重新定义...以前定义过"

我知道有类似的问题,但在我的案例中没有一个工作.嗨,我找不到为什么我有这个问题.这是我的个人文件:

#ifndef INDIVIDUAL_H
#define INDIVIDUAL_H

#include <vector>
#include <stdlib.h>
#include <time.h> 
#include <iostream>


using namespace std;

class Individual{
    private:
        vector<unsigned int> chromosome;
        unsigned int n_genes;
        unsigned int N_colours_used = 0;
        unsigned int fitness = 0;

    public:
        Individual(unsigned int ngenes){};

};

#endif
Run Code Online (Sandbox Code Playgroud)

这是我的个人.cpp文件:

#include "individual.h"


Individual :: Individual(unsigned int ngenes){
    cout << "something" << endl;
}
Run Code Online (Sandbox Code Playgroud)

错误看起来像这样

src/individual.cpp:4:1: error: redefinition of ‘Individual::Individual(unsigned int)’
Individual :: Individual(unsigned int ngenes){
 ^
In file included from src/individual.cpp:1:0:
include/individual.h:24:13: note: ‘Individual::Individual(unsigned int)’ previously defined here …
Run Code Online (Sandbox Code Playgroud)

c++ gcc makefile g++ c++11

-2
推荐指数
1
解决办法
467
查看次数

如何缩短Makefile中的路径?

我正在为 C++ 项目编写 Makefile 并希望缩短这些行,因为我注意到它们共享相同的模式:

IPATH = /lib/inc
OPATH = /lib/build
SPATH = /lib/src 
Run Code Online (Sandbox Code Playgroud)

我想出了类似的东西

{I,O,S}PATH = /lib/{inc,build,src}

(这似乎很愚蠢并且无论如何都会失败)。

有没有办法缩短上面的那些行?

谢谢你。

makefile

-2
推荐指数
1
解决办法
122
查看次数

为什么项目中没有包含必要的头文件?

我经常下载一个 C/C++ 项目并试图编译它只是为了玩它。几乎 100% 的时间makeorconfigure命令失败,我都会沿着依赖树的一部分走下去,遇到一个我不知道如何解决的错误,然后放弃。这可能是一个比头文件更广泛的问题,但似乎该make过程经常需要在特定位置为特定版本的库提供一些 .h 文件,而我的系统上没有这些文件。

如果项目需要这些特定的头文件,作者为什么不将它们复制到项目源代码树中呢?一般来说,要求以这种特定方式设置开发机器是不是很疯狂?如果有人想在两个项目上工作,并且他们需要头文件的冲突版本怎么办?

一个明显的解决方案是在构建过程中包含一个 Dockerfile,但我感兴趣的是这种情况最初是如何出现的,以及是否有一些理由不只包含必要的头文件,这似乎至少是部分解决方案.

c c++ makefile header-files

-2
推荐指数
1
解决办法
87
查看次数

标签 统计

makefile ×10

c ×6

c++ ×3

linux ×3

g++ ×2

gcc ×2

gnu-make ×2

shell ×2

bash ×1

c++11 ×1

gnu ×1

header-files ×1