LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   When compiling code with make, where does the compiled result go? (https://www.linuxquestions.org/questions/programming-9/when-compiling-code-with-make-where-does-the-compiled-result-go-4175686597/)

Paczki 12-10-2020 01:30 AM

When compiling code with make, where does the compiled result go?
 
When I run “make” on source code, where do the compiled files go?

Thanks.

berndbausch 12-10-2020 02:29 AM

That depends on the Makefile. If no Makefile exists, I believe the result is in the current directory.

EDIT: You may benefit from the introduction to makefiles in the GNU Make manual.

Paczki 12-10-2020 02:43 AM

Thank you.

Michael Uplawski 12-10-2020 06:55 AM

Quote:

Originally Posted by berndbausch (Post 6193802)
That depends on the Makefile. If no Makefile exists, I believe the result is in the current directory.

If no makefile exists, make won't run like that. But the choices are never so numerous. Either the new binary is in the current directory or in one of the sub-directories. Most of the time, in my experience, there is "bin". If not, the binary may be produced right beside the source-files in "src". There are cases, where platform-specific subdirectories should be scrutinized. I have also one package that allows Gnu-Make or CMake and drops the binary in the pertinently named sub-directory.

Searching *all these* and even more, is not an immensly long process. Human logic applies in pratically all packages that I compile.., even my own.

:) Cheerio

P.S.: when working in the w3m browser the edit button below my post is labelled "Edit Mess". How did you know me that well...

wpeckham 12-10-2020 06:59 AM

Check your source for README and INSTALL files. They often have the detail you are looking for.

If you have been doing this for a long time, you can read the Makefile directly (or the config file used to create the Makefile, if it exists.)

berndbausch 12-10-2020 07:37 AM

Quote:

Originally Posted by Michael Uplawski (Post 6193869)
If no makefile exists, make won't run like that.

It will:
Code:

$ ls
hi.c
$ make hi
cc    hi.c  -o hi
hi.c:1:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
 main(){printf("hi!\n");}
 ^
... warning messages ...
$ ./hi
hi!
$


Michael Uplawski 12-10-2020 03:22 PM

Quote:

Originally Posted by berndbausch (Post 6193880)
It will:

It does. I stand corrected. And it calls the right compiler, gcc or g++.

GazL 12-11-2020 04:40 AM

Quote:

Originally Posted by Michael Uplawski (Post 6194108)
It does. I stand corrected. And it calls the right compiler, gcc or g++.

Yes, as long as you're not compiling via intermediate .o files: where it will assume C rather than C++ for the link.
Code:

$ ls
"example1.c"  "example2.cc"
$ make example1.o example1
cc    -c -o example1.o example1.c
cc  example1.o  -o example1
$ make example2.o example2
g++    -c -o example2.o example2.cc
cc  example2.o  -o example2
/usr/bin/ld: example2.o: warning: relocation against `_ZSt4cout' in read-only section `.text'
/usr/bin/ld: example2.o: in function `main':
example2.cc:(.text+0xe): undefined reference to `std::cout'
/usr/bin/ld: example2.cc:(.text+0x13): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: example2.cc:(.text+0x1d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/bin/ld: example2.cc:(.text+0x28): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/bin/ld: example2.o: in function `__static_initialization_and_destruction_0(int, int)':
example2.cc:(.text+0x58): undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: example2.cc:(.text+0x6d): undefined reference to `std::ios_base::Init::~Init()'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [<builtin>: example2] Error 1
$ rm example2.o && make example2
g++    example2.cc  -o example2
$


pan64 12-11-2020 05:05 AM

Quote:

Originally Posted by Michael Uplawski (Post 6194108)
It does. I stand corrected. And it calls the right compiler, gcc or g++.

make comes with predefined (default) rules. If that works no makefile needed.
But those default rules are often not really suitable for real work.

Michael Uplawski 12-11-2020 02:46 PM

Quote:

Originally Posted by pan64 (Post 6194289)
make comes with predefined (default) rules. If that works no makefile needed.
But those default rules are often not really suitable for real work.

As I learned this yesterday, only, I could not come up with possible – so called “serious” – uses other than tiny quick examples.

onebuck 12-12-2020 10:22 AM

Moderator Response
 
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.

NevemTeve 12-12-2020 10:33 AM

Is there any unanswered questions?

Michael Uplawski 12-13-2020 07:24 AM

Quote:

Originally Posted by NevemTeve (Post 6194711)
Is there any unanswered questions?

:D Maybe not, but someone who finds the thread later can be comforted and maybe less alienated by a lax handling of the forum conventions. All is theory; you have to want and I am always glad to see people want something.


All times are GMT -5. The time now is 01:46 AM.