C
Christopher M. Lusardi
Hello,
THE PROBLEM
-----------
If I compile parts of my program with CC, and C, using extern "C" as
appropriate it compiles without any errors, but it does a segmentation
fault when I run the program.
The variables involved in the segmentation fault are surrounded by
compiler directives. I am 100% sure that I do not have to extern "C"
them.
UNRELATED EXAMPLE
=================
An example of using extern "C" is below to only show it. This is not
the program that I am referring to above. This example is for
unrelated background.
main.cpp
--------
extern "C" void test (int my_guess);
int main ()
{
int my_guess = 12580;
test (my_guess);
}
test.c
------
void test (int my_guess)
{
printf ("my_guess is %d\n",my_guess);
}
Compilation
-----------
cc -c test.c
CC main.c test.o
WHAT CAN I DO
-------------
What do you think the problem is? If I take the same program and
compile it just using the c compiler(using cc) without the extern
"C"'s the program compiles and runs perfectly! Could it be a
pre-compiler directive causing this? In both instance, where it would
run or not run I used the exact same makefile. The only change I made
in the makefile was to change CC to cc or vice versa. Should I just
step through my code with dbx to find the problem?
WHY I AM COMPILING THIS WAY
---------------------------
The reason that I want to be able to compile parts of the program with
CC and cc is I "have to" compile later with a C++ library which has a
lot of statements not in the C language.
Thank you,
Christopher Lusardi
THE PROBLEM
-----------
If I compile parts of my program with CC, and C, using extern "C" as
appropriate it compiles without any errors, but it does a segmentation
fault when I run the program.
The variables involved in the segmentation fault are surrounded by
compiler directives. I am 100% sure that I do not have to extern "C"
them.
UNRELATED EXAMPLE
=================
An example of using extern "C" is below to only show it. This is not
the program that I am referring to above. This example is for
unrelated background.
main.cpp
--------
extern "C" void test (int my_guess);
int main ()
{
int my_guess = 12580;
test (my_guess);
}
test.c
------
void test (int my_guess)
{
printf ("my_guess is %d\n",my_guess);
}
Compilation
-----------
cc -c test.c
CC main.c test.o
WHAT CAN I DO
-------------
What do you think the problem is? If I take the same program and
compile it just using the c compiler(using cc) without the extern
"C"'s the program compiles and runs perfectly! Could it be a
pre-compiler directive causing this? In both instance, where it would
run or not run I used the exact same makefile. The only change I made
in the makefile was to change CC to cc or vice versa. Should I just
step through my code with dbx to find the problem?
WHY I AM COMPILING THIS WAY
---------------------------
The reason that I want to be able to compile parts of the program with
CC and cc is I "have to" compile later with a C++ library which has a
lot of statements not in the C language.
Thank you,
Christopher Lusardi