cannot specify -o when generating multiple output files [C error]


I have a question about make file using gcc, below is my code in makefile. I got cannot specify -o when generating multiple output files error, but I just cant see where the problem is. Can someone point out my mistakes? Thanks!

BASE_FILES=bwtsearch.c bwtsearch.h bwttext.c bwttext.h chartable.c chartable.h common.h occtable.c occtable.h plset.c plset.h strbuf.c strbuf.h BASE_ENCODER_FILES=bwtencoder.h bwtencoder.c BWTSEARCH_FILES=${BASE_FILES} main_bwtsearch.c BENCODE_FILES=${BASE_ENCODER_FILES} main_bencode.c PSEARCH_FILES=${BASE_FILES} main_psearch.c PSEARCH_NL_FILES=${BASE_FILES} main_psearch_nl.c PENCODE_FILES=${BASE_ENCODER_FILES} main_pencode.c PENCODE_NL_FILES=${BASE_ENCODER_FILES} main_pencode_nl.c DEBUG_FILES=${BASE_FILES} main_debug.c all: bwtsearch psearch psearch_nl pencode pencode_nl bencode clean: rm psearch psearch_nl bwtsearch pencode pencode_nl bencode bwt_debug bwtsearch: ${BWTSEARCH_FILES} gcc -o bwtsearch ${BWTSEARCH_FILES} bencode: ${BENCODE_FILES} gcc -o bencode ${BENCODE_FILES} psearch: ${PSEARCH_FILES} gcc -o psearch ${PSEARCH_FILES} psearch_nl: ${PSEARCH_NL_FILES} gcc -o psearch_nl ${PSEARCH_NL_FILES} pencode: ${PENCODE_FILES} gcc -o pencode ${PENCODE_FILES} pencode_nl: ${PENCODE_NL_FILES} gcc -o pencode_nl ${PENCODE_NL_FILES} debug: ${DEBUG_FILES} gcc -o bwt_debug ${DEBUG_FILES}

below is the output of the console :)

gcc -o bwtsearch bwtsearch.c bwtsearch.h bwttext.c bwttext.h chartable.c chartable.h common.h occtable.c occtable.h plset.c plset.h strbuf.c strbuf.h main_bwtsearch.c clang: error: cannot specify -o when generating multiple output files make: *** [bwtsearch] Error 1


There should be no need to put header files in the list of files to be compiled, since a stylistically correct header file generates no executable code.

It used to be the case that it was mostly harmless to put header files in the gcc command line, because the compiler would add no executable content to the output file as a result of parsing and compiling a header. However, since gcc version 4 or so, and for roughly the same amount of time for clang, header files on the command-line are compiled into precompiled headers for use in later compile steps.

That means that compiling

gcc x.c y.h

will create <em>two</em> products: an executable generated from x.c and a precompiled header generated from y.h.

Gcc (at least up to version 6.3) lets you specify an explicit output filename in this case, although I believe the consequence is that the precompiled header file is written as x and then overwritten by the executable. (It doesn't let you specify an explicit output name in most other cases, such as when you use the -c, -S or -E options to produce an output for every input.) But clang, possibly more sensibly, produces an error when you an explicit output filename with the -o option and you have more than one output, even when that output is a precompiled header (which you possibly didn't intend to produce).

(Confusingly, on Mac OS X, the command gcc normally invokes the clang compiler. I suppose this is to avoid breaking scripts which incorrectly believe that gcc is the generic name for a C compiler.)

The solution is to remove the header files from the list of files to be compiled.


  • Problem creating info hash of torrent file
  • Can we stream only flash videos throught RTMP?
  • xp_regread() returned error 5, 'Access is denied.'
  • Modifying files nested in tar archive
  • Cannot find “Grammar.txt” in python-sphinx
  • Rodeo UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal
  • Loading Bitmap to ImageView from URL in android
  • Accessing Rows In A LINQ Result Without A Foreach Loop?
  • Why doesnt this Java loop in a thread work?
  • Get a trait object reference from a vector
  • Connecting bluetooth device to windows phone 8 application
  • Change Checkbox value without raising event
  • Can my PDF ping my server when it is opened?
  • PushKit for VOIP iOS apps
  • How to draw a line dynamically in android [duplicate]
  • allocating memory to an array of string
  • import scipy.sparse failed
  • Bash if statement with multiple conditions
  • Android changing fragment order inside FragmentPagerAdapter
  • IE11 throwing “SCRIPT1014: invalid character” where all other browsers work
  • How to disable all widgets inside Panel or inside Composite?
  • Set matplotlib plot axis to be the dataframe column name
  • Get history of file changes from TFS to implement custom “blame”-behaviour of exceptions
  • onBackPressed() not being executed
  • Passing 1 of 3 values to a Sub
  • debug library loaded with ctypes using gdb
  • How to install a .deb file on a jailbroken iphone programmatically?
  • How to use an array of arrays with array_map(…) in PHP?
  • How to rebase a series of branches?
  • All Classes Conforming to Protocol Inherit Default Implementation
  • Ajax jQuery multiple calls at the same time - long wait for answer and not able to cancel
  • Perl system calls when running as another user using sudo
  • Statically linking a C++ library to a C# process using CLI or any other way
  • Adding custom controls to a full screen movie
  • SVN: Merging two branches together
  • Load html files in TinyMce
  • Change div Background jquery
  • How does Linux kernel interrupt the application?
  • Busy indicator not showing up in wpf window [duplicate]
  • Why do underscore prefixed variables exist?