I have several object files coming from different directories (they are stored near the corresponding source that generated them). Is there a way that given this directory structure
Root
main.o
Root/Some_long_path
object_1.o
object_2.o
I could run a command like this
g++ -Wall main.o -ISome_long_path object_1.o object_2.o -o app
So that I don't have to put the full path in front of every object file. What would go instead of the -I command?
I am using gcc version 4.8.3 (from Cygwin installation).
So that I don't have to put the full path in front of every object file. What would go instead of the
-I
command?
There is no gcc option like -I
to add some directory to the object "search path", and there is no search path for objects. But there is search path for libraries (usually named lib*.a
for static libraries and lib*.so
for shared libraries in Unix world).
Directory-Options manual of gcc lists only -I
option for include paths and -L
option for library paths. There is no object path:
https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html#Directory-Options
And Link-Options manual of gcc mention only -L
option (near -l
description):
https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html#Link-Options
What can you use:
OBJ_DIR=./path/to/dir
then g++ ... $OBJ_DIR/obj1.o $OBJ_DIR/obj2.o
)libSome_Long_Component_Name.a
(this type of library is just like the archive of several *.o
object files and some extra info made with ar rcs
); then you can use g++ ... -Ldir/ -lSome_Long_Component_Name
Makefile
s and some variant of make utility (gnu make for linux and cygwin, nmake for windows's MSVC; you can start from gnu make manual: http://www.gnu.org/software/make/manual/make.html#Simple-Makefile then "2.4 Variables Make Makefiles Simpler" then "4.3 Types of Prerequisites" - with example of addprefix
command to ask make find objects in some objdir. There is also VPATH special variable which instructs make to search sources and objects in several directories; but all objects in project should have different names).Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments