I trying running C program with python. i want to get the NUMBER from one of the param file in params folder: params-example-one , params-example-two, params-example-three. i not sure why the code is not working. i get the error:
gcc -Wall -O3 -DPARAMS -c -o state.o state.c
In file included from state.h:13,
from state.c:1:
params.h:4:37: fatal error: params/params-1.h: No such file or directory
4 | #include xstr(params/params-PARAMS.h)
| ^
compilation terminated.
make: *** [<builtin>: state.o] Error 1
i want to choose the the right param file from python code.
the files looks like this:
params-example-one/two/three
#ifndef PARAMS_EXAMPLE_H
#define PARAMS_EXAMPLE_H
#define NUMBER 1 //2 or 3
#endif
this is my param.h file:
#define str(s) #s
#define xstr(s) str(s)
#include xstr(params/params-PARAMS.h)
makefile:
CC = gcc
CFLAGS = -Wall -O3 -DPARAMS$(PARAMS)
LDFLAGS = -lcrypto -lm
OBJFILES = state.o benchmark.o
TARGET = benchmark
all: $(TARGET)
$(TARGET): $(OBJFILES)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJFILES) $(LDFLAGS)
clean:
rm -f $(OBJFILES) $(TARGET) *~
state.c
#include "state.h"
void print_number() {
printf("%d", NUMBER);
}
state.h
#ifndef STATE_H
#define STATE_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#include <openssl/bn.h>
#include <limits.h>
#include "params.h"
void print_number() ;
#endif
benchmark.c
#define _POSIX_C_SOURCE 199309L
#include <stdio.h>
#include <stdlib.h>
#include "state.h"
int main()
{
print_number();
}
benchmark.py
#! /usr/bin/env python3
import fileinput
import itertools
import os
import sys
from subprocess import DEVNULL, run
file_number = ["one"]
paramset = "example-{}".format(file_number[0])
paramfile = "params-{}.h".format(paramset)
print("Benchmarking", paramset, flush=True)
params = 'PARAMS={}'.format(paramset)
run(["make", "clean"], stdout=DEVNULL, stderr=sys.stderr)
run(["make", params], stdout=DEVNULL, stderr=sys.stderr)
run(["./benchmark"],stdout=sys.stdout, stderr=sys.stderr)
print(flush=True)
i try to run the code without the benchmark.py and without params-example-one , params-example-two, params-example-three. i just use the param.h with #define NUMBER 1, and its working. but this is not what I expecting. i want to choose the right param file in python code.
You are missing an =
sign in the makefile:
CFLAGS = -Wall -O3 -DPARAMS=$(PARAMS)
# ^ here
The compiler output doesn't correspond to the code you provided though.