0

I'm trying to create a communication channel between two devices, such as two computers, that will work with the cryptographic network protocol Salt channelv2 and forward data to each other. I created 2 applications, where the first application demonstrates the functionality of the Salt channelv2 protocol and the second application creates a secure communication channel (specifically using the TCP / IP model). Applications are working, I compiled them using linking in the CLI and now I am trying to create a makefile file for easy compilation of the program for the user.

This is my Makefile:

 CC=gcc
CFLAGS=-O2 -Wall -g -fcommon  -I./salt_org -I./header_folders  -I./library
#LDFLAGS= 

all:program

program: salt_buffer.o libcrypto.a
    $(CC) $(CFLAGS) -o program.exe salt_buffer.o libcrypto.a

randombytes.o: randombytes.c
    $(CC) $(CFLAGS)  -c randombytes.c

tweetnacl_modified.o: tweetnacl_modified.c tweetnacl_modified.h
    $(CC) $(CFLAGS)  -c tweetnacl_modified.c

tweetnacl_modified_wrapper.o: tweetnacl_modified_wrapper.c
    $(CC) $(CFLAGS) -c tweetnacl_modified_wrapper.c

salt.o: salt.c salt.h salti_handshake.h salti_util.h
    $(CC) $(CFLAGS) -c salt.c

salt_io.o: salt_io.c salti_util.h 
    $(CC) $(CFLAGS) -c salt_io.c

salti_handshake.o: salti_handshake.c salti_handshake.h
    $(CC) $(CFLAGS) -c salti_handshake.c

salti_util.o: salti_util.c salti_util.h
    $(CC) $(CFLAGS) -c salti_util.c

salt_modified.o: salt_modified.c salt_modified.h salt.h
    $(CC) $(CFLAGS) -c salt_modified.c

salt_buffer.o: salt_buffer.c header_folders/salt.h \
    header_folders/salti_handshake.h header_folders/salti_util.h \       
    header_folders/salt_modified.h header_folders/salt_io.h 
    $(CC) $(CFLAGS) -c salt_buffer.c 

libcrypto.a: salt.o salti_handshake.o salti_util.o salt_io.o tweetnacl_modified_wrapper.o \
    tweetnacl_modified.o randombytes.o salt_modified.o
    ar -cvq -o libcrypto.a salt.o salti_handshake.o salti_util.o salt_io.o \
    tweetnacl_modified_wrapper.o tweetnacl_modified.o randombytes.o salt_modified.o
    
clean:
    rm -f program *.o *.a hlavickove_subory/*.gch

In one folder are source codes and folders such as salt_org, header_folders, library, salt_buffer.c, salt_modified.c and makefile. The main program is salt_buffer.c and salt_modified.c contains the source file I supplied with the body functions needed for the application that salt_buffer.c works with. With auxiliary source codes I try to create a static library libcrypto.a. Source codes such as randombytes.c, tweetnacl_modified.c, tweetnacl_modified_wrapper.c are in the library folder. Other source codes such as salt.c, salti_handshake.c, salti_util.c, salt_io.c are in the salt_org folder. All the header files I use are in the header_folders folder.

At work, I was inspired by the topic: enter link description here.

The problem I get when running the makefile file is: gcc -o .o gcc.exe: fatal error: no input files compilation terminated. make: *** [: .o] Error 1

In source files, I have paths to files like this for example salt_buffer.c:

#include "salt.h"
#include "salt_io.h"
#include "salti_util.h"
#include "salti_handshake.h"
#include "salt_modified.h"

I work with the Winlibs compiler with 11.2 Can you please advise me about my errors ?

1 Answers1

1

First, when asking questions like this you should always include (via cut and paste) the actual compile line that generated the errors, not just the errors. The reason for errors like this is always found on the compile line.

Second, your problem is that you should never include the header files on the compile line. The compiler will include the headers because of the #include ... commands inside the source file: you must not include them on the compilation line as well. Rules like this:

salt.o: salt.c salt.h salti_handshake.h salti_util.h
        $(CC) $(CFLAGS) -c salt.c salti_handshake.h salti_util.h

should simply be:

salt.o: salt.c salt.h salti_handshake.h salti_util.h
        $(CC) $(CFLAGS) -c salt.c

and that's all. Ditto for all other recipes where header files appear on the compilation line.

There are many better ways to write this makefile so you don't have to repeat yourself so many times, but fixing the above should allow your current makefile to work properly.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • IIANM, you're not supposed to specify include files as positional arguments to your C compiler. – einpoklum Aug 29 '21 at 20:24
  • I tried to fix salt.o according to your example and the error did not change. The line that lists the error from the makefile is the line (recipe for compiling salt_buffer.o) $ (CC) $ (CFLAGS) -c salt_buffer.c salt.h salt_io.h salti_util.h \ – Im not a robot Aug 30 '21 at 09:50
  • When I fixed the line in the makefile file to: salt_buffer.o: salt_buffer.c $ (CC) $ (CFLAGS) -c salt_buffer.c so it gives me a makefile make: *** No rule to make target 'salt.c', needed by 'salt.o'. Stop. ..But now I know that the line for compiling salt_buffer.o I have misspelled – Im not a robot Aug 30 '21 at 10:03
  • Above you said the error was it couldn't find `salt.h` and here you say it can't find `salt.c`. Which is correct? If it's `salt.h` then the problem is simple: you've told the compiler where to find the headers, but you didn't tell make where to find them. You need to use the real pathname (e.g., `header_folder/salt.h`) in your makefile prerequisites list. – MadScientist Aug 30 '21 at 13:42
  • I edited line to compile salt_buffer.o: salt_buffer.o: salt_buffer.c header_folder/salt.h \ header_folder/salti_util.h header_folder/salti_handshake.h \ header_folder/salt_io.h header_folder/salt_modified.h $(CC) $(CFLAGS) -c salt_buffer.c ....and this tells me gcc -o .o gcc.exe: fatal error: no input files compilation terminated. make: *** [: .o] Error 1 – Im not a robot Aug 31 '21 at 09:47
  • It's too hard to read formatted output in comments. Please edit your question and show the make command line you invoked and the output you got, cut and pasted into the question with proper formatting so it's readable. Also your current makefile. You have made a typo somewhere: very common when you're trying to write out everything directly rather than using make's various features that allow you to avoid duplication. If I had to guess I'd say that somewhere you've added a space before a ".o" where it shouldn't be, or something like that. – MadScientist Aug 31 '21 at 12:44