当我在本地机器上编写完脚本后,我需要将它们复制到集群中来执行代码。例如,我想将当前目录中的所有 matlab 文件复制到服务器 id@server 的目录中。
任何人都可以帮助编写一个非常基本的 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) 我写了一个函数,它检查字符字符串是否为回文。
//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) 我已经循环了,我需要添加到它的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) 来自文档:
该
include指令告诉make暂停读取当前的makefile并在继续之前读取一个或多个其他makefile.该指令是makefile中的一行,如下所示:Run Code Online (Sandbox Code Playgroud)include FILENAMES...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)
那么,这里发生了什么?我们显然有:
创建了一个Makefile,包含在:
$(shell echo 'all : ;' >makefile.include)
Run Code Online (Sandbox Code Playgroud)后来包含了这个makefile,因为我们可以使用"shell文件名模式",如文档中引用的那样 - 因此,我们在makefile中有:
include …Run Code Online (Sandbox Code Playgroud)我是Makefile的新手.我写了hello.c,当我做"make hello"时,它给出了一个名为"hello"的可执行文件.在内部显示"cc hello.c -o hello".但是没有Makefile怎么制作?如何使可执行文件与源名称相同?
我有一个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) 我知道有类似的问题,但在我的案例中没有一个工作.嗨,我找不到为什么我有这个问题.这是我的个人文件:
#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++ 项目编写 Makefile 并希望缩短这些行,因为我注意到它们共享相同的模式:
IPATH = /lib/inc
OPATH = /lib/build
SPATH = /lib/src
Run Code Online (Sandbox Code Playgroud)
我想出了类似的东西
{I,O,S}PATH = /lib/{inc,build,src}
(这似乎很愚蠢并且无论如何都会失败)。
有没有办法缩短上面的那些行?
谢谢你。
我经常下载一个 C/C++ 项目并试图编译它只是为了玩它。几乎 100% 的时间makeorconfigure命令失败,我都会沿着依赖树的一部分走下去,遇到一个我不知道如何解决的错误,然后放弃。这可能是一个比头文件更广泛的问题,但似乎该make过程经常需要在特定位置为特定版本的库提供一些 .h 文件,而我的系统上没有这些文件。
如果项目需要这些特定的头文件,作者为什么不将它们复制到项目源代码树中呢?一般来说,要求以这种特定方式设置开发机器是不是很疯狂?如果有人想在两个项目上工作,并且他们需要头文件的冲突版本怎么办?
一个明显的解决方案是在构建过程中包含一个 Dockerfile,但我感兴趣的是这种情况最初是如何出现的,以及是否有一些理由不只包含必要的头文件,这似乎至少是部分解决方案.