Jmake compiling the current directory for all C + + single files

Source: Internet
Author: User
Tags sprintf

In a directory to write some of the single-file C or C + + files, each time to knock out commands such as g++ a.cpp-o a feeling more troublesome.

So just imitate makefile function, realize scan current directory, and all C file, cc file, CPP file directly call gcc/g++ compile.

One of the drawbacks of this program is that it cannot be used for inter-file include cases, because it is cumbersome to scan the code for other files. And you cannot add options for other libraries in the compile command.

How to use:

1 Jmake

Source:

1 /*2 * author:huanglianjing3  * 4 * This was a program-to-compile all single C + + file of current directory5  * 6 * Usage:jmake7  */8 9#include <stdio.h>Ten#include <stdlib.h> One#include <unistd.h> A#include <dirent.h> -#include <string.h> -#include <sys/stat.h> the  - intMain () - { -     structDirent *entry; +     structstat statbuf; -      +DIR *DP = Opendir ("."); A      while((Entry=readdir (DP))! =NULL) { atLstat (entry->d_name,&statbuf); -         if(!S_isdir (Statbuf.st_mode)) { -             Charfname[ $], ename[ $], instruction[207]; -strcpy (fname,entry->d_name); -strcpy (ename,entry->d_name); -             intLen =strlen (fname); in             if(len>=3&& fname[len-1]=='C'&& fname[len-2]=='.') {//. C -ename[len-2] =' /'; tosprintf (instruction,"gcc%s-o%s", fname,ename); +printf"%s\n", instruction); - system (instruction); the             } *             Else if(len>=4&& fname[len-1]=='C' $&& fname[len-2]=='C'&& fname[len-3]=='.') {//. CCPanax Notoginsengename[len-3] =' /'; -sprintf (instruction,"g++%s-o%s", fname,ename); theprintf"%s\n", instruction); + system (instruction); A             } the             Else if(len>=5&& fname[len-1]=='P'&& fname[len-2]=='P' +&& fname[len-3]=='C'&& fname[len-4]=='.') {//. cpp -ename[len-4] =' /'; $sprintf (instruction,"g++%s-o%s", fname,ename); $printf"%s\n", instruction); - system (instruction); -             } the         } -     }Wuyi Closedir (DP); the     return 0; -}

Jmake compiling the current directory for all C + + single files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.