• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 417
  • Last Modified:

newbie prob: i get a linker error when i try to compile a program containing a system command

i get a linker error when i try to compile a program containing a system command.
here is the error i get:

Linker Error (Severity 4)
      Module "a" in file "c:\program files\miracle c\test10.obj"
      references unresolved external "_system"
      at offset 0025H in segment "_text".


i also get a similar error when i use a stat or access command.
is it a problem with my code or the compiler. in either case: how do i fix?
0
ico2
Asked:
ico2
  • 16
  • 7
  • 2
  • +3
1 Solution
 
unityxx311Commented:
Hi, first off are you including the proper header files? Do a man access and man stat to determine what header files they are in.

These two are used quite often.
#include<stdio.h>
#include<stdlib.h>
Secondly, you need to post your code.

m.
0
 
ico2Author Commented:
i tried it using all the header files that came with my compiler and it doesn't work.
can anyone tell me what header file systemis in so that i can find somewhere to download it.
0
 
PerryDKCommented:
your header files are fine.  You'd be getting a compile time error if you weren't including the proper header files.

Linker errors can result from the linker not being able to find .obj, statically linked dll's, etc.

They can also be caused by something like this in a header file
extern int MY_GLOBAL;

but never declaring the actual variable in your .c file as
int MY_GLOBAL;

0
The IT Degree for Career Advancement

Earn your B.S. in Network Operations and Security and become a network and IT security expert. This WGU degree program curriculum was designed with tech-savvy, self-motivated students in mind – allowing you to use your technical expertise, to address real-world business problems.

 
ico2Author Commented:
can't be a bad header file because i get the same error even if i include no header files.
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi unityxx311,

Someplace in your program you are referencing the name 'system'.  Can you show us your source so that we can see how you're using it?

You're probably doing something like:

  int Variable = system;

  int Variable;
      Variable = system;

  SomeFunction (system);



Good Luck,
Kent
0
 
ico2Author Commented:
i am just using system("c:\\command.com")
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi ico2,

Ok.  Then you are probably not linking the correct library.  What environment are you using?


Kent
0
 
unityxx311Commented:
ico2,

I know sometimes you have to explictly state in your compile line to link certain libraries.
e.g.   gcc example.c -lm -lgsl

-lm link the math.h lib
-lgsl link the gsl lib

m.
0
 
ico2Author Commented:
kdo:
hi
i am using miracle c. which i got free of download.com so it is probably not very good.

unityxx311:
i do not understand what you are saying, can you make it simpler as i am relatively new to c programming.
0
 
waysideCommented:
For the Microsoft compiler, the "system" function is in the c runtime library.

It may be that the runtime library for the "miracle" compiler doesn't have this function. or you need to link to a different library; I'm not familiar with this compiler.

0
 
ico2Author Commented:
is it possible to download the library containing this function?
0
 
ico2Author Commented:
will someone please tell me how to fix this problem, is there a file i can download to fix this?
0
 
ico2Author Commented:
or would getting a different compiler fix the problem.
0
 
ankuratvbCommented:
Ok.try these programs:
#include<process.h>
int main()
{
 exit(0);
}

and
#include<stdlib.h>
int main()
{
 int i;
 i=atoi("123");
 return 0;
}

I am doing this becuase system is defined in process.h and stdlib.h
The first program calls a fn. included in process.h and the 2nd a fn. in stdlib.h

Changing the compiler will definitely solve ur problem but u shouldnt need to.

BTW,wasnt the system command working for u here:
http://oldlook.experts-exchange.com/Programming/Programming_Languages/C/Q_20944819.html
0
 
ico2Author Commented:
for the first one i get this error:

c:\Program Files\Miracle C\include\process.h: line 49: void variable illegal
'void __cdecl exit(int)'
aborting compile

but the second one works fine.
0
 
ankuratvbCommented:
So ur compiler can link to stdlib.h correctly.

if system() wasnt in the library for ur compiler it shouldve given u a compilation error.
0
 
ico2Author Commented:
am i right in assuming this is a very wierd error that is not normal
0
 
ankuratvbCommented:
To a certain extent,yes.

Can u try reinstalling the compiler or atleast copying the libraries again.

But wasnt ur system() command working when u asked the question about how to execute external commands and appending a string to another.

0
 
ico2Author Commented:
no it wasn't.
0
 
ico2Author Commented:
i am just trying that now
0
 
ankuratvbCommented:
Possibly some of ur library files may have been corrupted.
Try copying the libraries again in the lib path.
0
 
ico2Author Commented:
after uninstalling my compiler and re-installing-doesn't work.

after uninstalling and deleting the folder of my compiler-still doesn't work.
0
 
ico2Author Commented:
i am now looking for another free compiler, i will tell you if this works.
0
 
ico2Author Commented:
hmm i cannot find another free compiler, does anyone know of a good one?
0
 
ankuratvbCommented:
Try CYGWIN.Its a linux simulator for windows and has gcc,the gnu c compiler.
Its free and available at www.cygwin.com

0
 
ankuratvbCommented:
Turbo C version 2.01 can be downloaded from http://community.borland.com/article/0,1410,20841,00.html and is only just over 1M.

This is a pretty old compiler but pretty small in size/
0
 
ico2Author Commented:
wahay i downloaded the second one and it works great.
thanks so much!!!!
0
 
waysideCommented:
Isn't Turbo C a 16 bit compiler?
0
 
ankuratvbCommented:
Yeah.
Its from DOS days.

ico2,
Even though u have downloaded TC 2.01 ,i'd still recommend downloading cygwin.
gcc is a very good compiler and supports C99 features and has some pretty good extensions as well.
0
 
ico2Author Commented:
since a previous incident which i don't want to speak about i avoid using anything with linux in the title.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

  • 16
  • 7
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now