gnu

Issue with OpenMP reduction on std::vector passed by reference

瘦欲@ 提交于 2019-12-24 22:18:05
问题 There is a bug in intel compiler on user-defined reduction in OpenMP which was discussed here (including the wrokaround). Now I want to pass the vector to a function and do the same thing but I get this error: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted This is the example: #include <iostream> #include <vector> #include <algorithm> #include "omp.h" #pragma omp declare reduction(vec_double_plus : std::vector<double> : \ std::transform(omp_out

GLOB_BRACE portability?

房东的猫 提交于 2019-12-24 15:12:09
问题 In this question, I was made aware of glob()'s GLOB_BRACE option that allows for a limited set of regular expressions when searching for files. This looks just like what I need, but according to the manual, GLOB_BRACE is "not available on some Non-GNU Operating systems." Among those seems to be Solaris. I am building an application that is supposed to be as portable as possible, so I need to check out possible problems as early as possible. Does somebody know of other platforms apart from

The simplest possible getopt program I can get?

扶醉桌前 提交于 2019-12-24 13:24:04
问题 After doing some reading on this link on how to use getopt() , I'm trying to get a small example. What I want, is something like: ./prog -v # show me prog version ./prog -f filename # just show me the filename I entered from the command line Here is what I wrote so far: #include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, *argv[]) { char VER[] = "0.1.1"; int opt; opt = getopt(argc, argv, "vf:"); char *filename; while (opt != -1) { switch(opt) { case 'v': printf(

GNU make copy files to distro directory

时光怂恿深爱的人放手 提交于 2019-12-24 11:45:01
问题 I keep my source html (and images etc.) in separate directories for source control. Part of making the distro is to have make copy files to output folder and set the attributes. Today my makefile shows (extract): %.html: /usr/bin/install -c -p -m 644 $< $@ www: $(HTMLDST)/firmware.html $(HTMLDST)/firmware_status.html $(HTMLDST)/index.html $(HTMLDST)/firmware.html: $(HTMLSRC)/firmware.html $(HTMLDST)/firmware_status.html: $(HTMLSRC)/firmware_status.html $(HTMLDST)/index.html: $(HTMLSRC)/index

How to prevent GNU Make from executing when a variable definition has trailing spaces

故事扮演 提交于 2019-12-24 10:20:12
问题 I had a simple variable definition in my makefile: THIS := ~/edan and it had trailing spaces in the line. Later, when I defined another variable in terms of this one: WARES := $(THIS)/wares the actual variable defined was /home/directory/edan wares and then the make clean rule removed /home/directory/edan instead of what I wanted it to. How can I prevent a makefile from executing if a line has trailing spaces? 回答1: Although you could write the Makefile so that it checks the variable for

How to compute the range in Makefile

风格不统一 提交于 2019-12-24 09:57:29
问题 Here is my Makefile and the output, how to print the range like [1-5, 7, 9-10] ? $ ls /tmp/foo foo10.txt foo1.txt foo2.txt foo3.txt foo4.txt foo5.txt foo7.txt foo9.txt $ cat Makefile DIR1 := /tmp/foo/ COMMA :=, EMPTY := SPACE := $(EMPTY) $(EMPTY) VERSIONS := $(subst $(SPACE),$(COMMA),$(patsubst foo%,%,$(basename $(notdir $(wildcard $(DIR1)/foo*.txt))))) all: $(info versions is [${VERSIONS}]) $ make versions is [10,1,2,3,4,5,7,9] 回答1: Here is pipeline of shell commands to get your job done:

removing line from list using sort, grep LINUX

邮差的信 提交于 2019-12-24 08:49:03
问题 I have a list that looks like: #Population, Year, County 3900, 1969, Beaver 3798, 1970, Beaver 3830, 1971, Beaver 3864, 1972, Beaver 3993, 1973, Beaver 3976, 1974, Beaver 4064, 1975, Beaver 4074, 1976, Beaver 4064, 1977, Beaver 4194, 1978, Beaver 4240, 1979, Beaver The list is much longer but I did not include the rest. I used grep to filter the list to get only the years 1989, and then sorted it by population going from most populated to least populated, but I encountered an issue. 719048,

How to build multiple targets with similar name?

我是研究僧i 提交于 2019-12-24 07:43:54
问题 So I have the exact same question as the one below, but no one has answered it. Pattern matching Makefile with multiple executable targets I am trying to build a series of small test files each have a pattern of "test*.c" to test my library. I wanted to write a makefile that builds executables for every one of the test files all at once (each name: test1, test2, test3..etc.). However, I am not sure how to achieve that. What I have so far is the following: SRC := $(shell find *.c) ALL_PROG :=

How to build multiple targets with similar name?

这一生的挚爱 提交于 2019-12-24 07:42:05
问题 So I have the exact same question as the one below, but no one has answered it. Pattern matching Makefile with multiple executable targets I am trying to build a series of small test files each have a pattern of "test*.c" to test my library. I wanted to write a makefile that builds executables for every one of the test files all at once (each name: test1, test2, test3..etc.). However, I am not sure how to achieve that. What I have so far is the following: SRC := $(shell find *.c) ALL_PROG :=

gcc常用编译选项

☆樱花仙子☆ 提交于 2019-12-24 07:02:18
“-Wall”选项打开所有最常用到的编译警告,强烈建议打开,可以捕捉到许多在C编程中最常发生的错误。 “-o”选项来为可执行文件指定一个不同的输出文件。 “-c”用于把源码文件编译成对象文件。 对象文件包含的是机器码,其中任何对在其他文件中的函数(或变量)的内存地址的引用都留着没有被解析。这样就允许在互相之间不直接引用的情况下编译各个源代码文件。链接器在生成可执行文件时会填写这些还缺少的地址,然后把所有的对象文件组合在一起生成单个的可执行文件。当用“-c”来编译时,编译器会自动生成与源文件同名,但用“.o”来代替原来的扩展名的对象文件。 gcc使用链接器ld来施行链接,它是一个单独的程序。在GNU系统上用到的是GNU的链接器,即GNU ld。 通常,链接要快于编译----在一个有许多源文件的大型项目中,只重新编译那些被修改过的文件可以显著地节省时间。仅仅重编译项目中修改过的文件的过程可以用GNU Make来自动完成。 标准的系统库通常能在“/usr/lib”和“/lib”目录下,C标准库自身存放在“/usr/lib/libc.a”中,包含ANSI/ISO C标准指定的各个函数。其他库都需要显示或隐示指定。 “-lNAME”试图链接标准库目录下的文件名为“libNAME.a”中的对象文件。在大型程序中通常会用到很多“-l”选项,来链接象数学库,图形库和网络库。使用选项“-lNAME