Sponsored Content
Full Discussion: Makefile Mix for C and C++
Top Forums Shell Programming and Scripting Makefile Mix for C and C++ Post 302703097 by DGPickett on Wednesday 19th of September 2012 10:37:05 AM
Old 09-19-2012
When you want to reference C++ variables in C, you must declare them in C using the wrapper "extern C++ { . . . }", even by way of include file #include lines, and vice-versa with "extern C { . . . }". C++ names are mangled to indicate the type returned and, if method/subroutine/function, the number and types of arguments, for stricter type checking. The original C++ compilers were just preprocessors for the C compiler. If you look at some object code (executables and libraries) using nm, you will see the mangled names of C++ identifiers.

Your make rules need to point to different compiler commands and arguments, using different variables, e.g., not swapping CC from gcc to g++. Sometimes it simplifies things if you use a different directory, or ensure even include files have different suffixes for c++. Try not to make whole new compile lines for every file, but just modify a variable referenced in the common line for moving from one extension to the next. If object file order on linking line is getting to be a pain, remember that code is library files, static or dynamic, is not order sensitive. Even main() can be in a library if all the code in the library serves that main. One class per include file and one subroutine/method/class per non-include file, all compiled -c and non-main() .o put in libraries, is a good practice.

Last edited by DGPickett; 09-19-2012 at 11:47 AM..
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to grep mix of numbers and systemdate?

Hi Guys, i'm beginner in UNIX commands, need some help on this simple question: I need to make a shell script to move files to another directory, the criterias are : 1. the range of 4 last digit of the file name is 0100-0199 2. move all files that processed daily (let's say today is... (2 Replies)
Discussion started by: saltshaker
2 Replies

2. AIX

mix fc and tape devices

I have a problem with some partitions. In one of them I have this two fiber channel. lsdev -Cc adapter ent0 Available 03-08 10/100/1000 Base-TX PCI-X Adapter (14106902) fcs0 Available 04-08 FC Adapter fcs1 Available 05-08 FC Adapter ide0 Defined 07-08 ATA/IDE... (0 Replies)
Discussion started by: lo-lp-kl
0 Replies

3. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

4. Solaris

ZFS Pool Mix-up

Hi all I plan to install Solaris 10U6 on some SPARC server using ZFS as root pool, whereas I would like to keep the current setup done by VxVM: - 2 internal disks: c0t0d0 and c0t1d0 - bootable root-volume (mirrored, both disks) - 1 non-mirrored swap slice - 1 non-mirrored slices for Live... (1 Reply)
Discussion started by: blicki
1 Replies

5. Shell Programming and Scripting

How to mix the contents of 2 files into a new file?

Hello Everybody! My question is how can I mix for example file_a with file_b in the following method: After 2 lines of file_a put 2 lines from file_b to file_c. For example: file_a: 1 2 3 4 5 6 file_b: 11 22 (7 Replies)
Discussion started by: Levi85
7 Replies

6. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

7. Programming

makefile for mix of C and C++ modules

I am trying to come up with a makefile where the target is linked with object files produced by C and C++ sources. My setup is Ubuntu/gcc: $ uname -a Linux srvr1 2.6.24-24-server #1 SMP Fri Sep 18 17:24:10 UTC 2009 i686 GNU/Linux gcc version 4.2.4 $ cat main.cpp #include <iostream>... (6 Replies)
Discussion started by: migurus
6 Replies

8. AIX

Mix LDAP and LOCAL user on AIX

Hello, I'm currently trying to mix local and LDAP users on an AIX 7.1. I've triied many things. My LDAP Server in on a CentOS - OpenLDAP (which works fine with linux). I'm currently stuck on AIX at how to declare LDAP AND Local users. Here's what i did : /usr/sbin/mksecldap -c -h 'ldap03'... (15 Replies)
Discussion started by: AIX_user_324891
15 Replies
2C(1)							      General Commands Manual							     2C(1)

NAME
2c, 6c, 8c, kc, vc, xc - C compilers SYNOPSIS
2c [ option ... ] [ file ... ] 6c [ option ... ] [ file ... ] 8c [ option ... ] [ file ... ] kc [ option ... ] [ file ... ] vc [ option ... ] [ file ... ] xc [ option ... ] [ file ... ] DESCRIPTION
2c, 6c, 8c, kc, vc, and xc compile the named C files into MC68020, i960, i386, SPARC, MIPS, and ATT3210 object files. The compilers handle most preprocessing directives themselves; a complete preprocessor is available in cpp(1), which must be run separately. Let the first letter of the compiler name be O= 2, 6, 8, k, v, or x. The output object files end in .O. The letter is also the prefix of related programs: Oa is the assembler, Ol is the loader. Associated with each compiler is a string objtype= 68020, 960, 386, sparc, mips, or 3210. Plan 9 conventionally sets the $objtype environment variable to the objtype string appropriate to the current machine's type. Plan 9 also conventionally has /objtype directories, which contain among other things: include, for machine-dependent include files; lib, for public object code libraries; bin, for public programs; and mkfile, for preconditioning mk(1). The compiler options are: -o obj Place output in file obj (allowed only if there is just one input file). Default is to take the last element of the input file name, strip any trailing .c, and append .O. -w Print warning messages about unused variables, etc. -B Accept functions without a new-style ANSI C function prototype. By default, the compilers reject functions used without a defined prototype, although ANSI C permits them. -Dname=def -Dname Define the name to the preprocessor, as if by If no definition is given, the name is defined as -Idir An file whose name does not begin with slash or is enclosed in double quotes is always sought first in the directory of the file argument. If this fails, or the name is enclosed in <>, it is then sought in directories named in -I options, then in /sys/include, and finally in /$objtype/include. -N Suppress automatic registerization and optimization. -S Print an assembly language version of the object code on standard output as well as generating the .O file. -a Instead of compiling, print on standard output acid functions (see acid(1)) for examining structures declared in the source files. -aa Like -a except suppress information about structures declared in included header files. The compilers support several extensions to ANSI C: - A structure or union may contain unnamed substructures and subunions. The fields of the substructures or subunions can then be used as if they were members of the parent structure or union (the resolution of a name conflict is unspecified). When a pointer to the outer structure or union is used in a context that is only legal for the unnamed substructure, the compiler promotes the type and adjusts the pointer value to point at the substructure. If the unnamed structure or union is of a type with a tag name specified by a typedef statement, the unnamed structure or union can be explicitly referenced by <struct variable>.<tagname>. - A structure value can be formed with an expression such as (struct S){v1, v2, v3} where the list elements are values for the fields of struct S. - Array initializers can specify the indices of the array in square brackets, as int a[] = { [3] 1, [10] 5 }; which initializes the third and tenth elements of the eleven-element array a. - Structure initializers can specify the structure element by using the name following a period, as int struct { int x; int y; } s = { .y 1, .x 5 }; which initializes elements y and then x of the structure s. - A global variable can be dedicated to a register by declaring it extern register in all modules and libraries. - A #pragma of the form #pragma lib "libbio.a" records that the program needs to be loaded with file /$objtype/lib/libbio.a; such lines, typically placed in library header files, obviate the -l option of the loaders. To help identify files in non-standard directories, within the file names in the #pragmas the string $M represents the name of the architecture (e.g., mips) and $O represents its identifying character (e.g., v). - The C++ comment (// to end of line) is accepted as well as the normal convention of /* */. - The compilers accept long long variables as a 64-bit type. The standard header typedefs this to vlong. The vlong runtime is slow. EXAMPLE
For the 68020, produce a program prog from C files main.c and sub.c: 2c -w main.c sub.c 2l -o prog main.2 sub.2 FILES
/sys/include system area for machine-independent #include directives. /$objtype/include system area for machine-dependent #include directives. SOURCE
/sys/src/cmd/cc machine-independent part /sys/src/cmd/2c, etc. machine-dependent part SEE ALSO
2a(1), 2l(1), cpp(1), mk(1), nm(1), pcc(1), db(1), acid(1), Rob Pike, ``How to Use the Plan 9 C Compiler'' BUGS
The i960 compiler has been used only to program one I/O controller and is certainly buggy. The preprocessor only handles and For a full ANSI preprocessor, use cpp(1) on the files first. 2C(1)
All times are GMT -4. The time now is 05:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy