Solved

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

Posted on 2004-04-06
30
405 Views
Last Modified: 2012-06-22
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
Comment
Question by:ico2
  • 16
  • 7
  • 2
  • +3
30 Comments
 

Expert Comment

by:unityxx311
ID: 10768745
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
 
LVL 1

Author Comment

by:ico2
ID: 10768836
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
 
LVL 4

Expert Comment

by:PerryDK
ID: 10768945
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
 
LVL 1

Author Comment

by:ico2
ID: 10768999
can't be a bad header file because i get the same error even if i include no header files.
0
 
LVL 45

Expert Comment

by:Kdo
ID: 10769080
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
 
LVL 1

Author Comment

by:ico2
ID: 10769132
i am just using system("c:\\command.com")
0
 
LVL 45

Expert Comment

by:Kdo
ID: 10769219
Hi ico2,

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


Kent
0
 

Expert Comment

by:unityxx311
ID: 10769549
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
 
LVL 1

Author Comment

by:ico2
ID: 10769710
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
 
LVL 14

Expert Comment

by:wayside
ID: 10769882
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
 
LVL 1

Author Comment

by:ico2
ID: 10769897
is it possible to download the library containing this function?
0
 
LVL 1

Author Comment

by:ico2
ID: 10773080
will someone please tell me how to fix this problem, is there a file i can download to fix this?
0
 
LVL 1

Author Comment

by:ico2
ID: 10773094
or would getting a different compiler fix the problem.
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10773298
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
 
LVL 1

Author Comment

by:ico2
ID: 10773316
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 9

Expert Comment

by:ankuratvb
ID: 10773367
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
 
LVL 1

Author Comment

by:ico2
ID: 10773388
am i right in assuming this is a very wierd error that is not normal
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10773408
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
 
LVL 1

Author Comment

by:ico2
ID: 10773517
no it wasn't.
0
 
LVL 1

Author Comment

by:ico2
ID: 10773522
i am just trying that now
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10773579
Possibly some of ur library files may have been corrupted.
Try copying the libraries again in the lib path.
0
 
LVL 1

Author Comment

by:ico2
ID: 10773677
after uninstalling my compiler and re-installing-doesn't work.

after uninstalling and deleting the folder of my compiler-still doesn't work.
0
 
LVL 1

Author Comment

by:ico2
ID: 10773883
i am now looking for another free compiler, i will tell you if this works.
0
 
LVL 1

Author Comment

by:ico2
ID: 10775115
hmm i cannot find another free compiler, does anyone know of a good one?
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10775187
Try CYGWIN.Its a linux simulator for windows and has gcc,the gnu c compiler.
Its free and available at www.cygwin.com

0
 
LVL 9

Accepted Solution

by:
ankuratvb earned 25 total points
ID: 10775250
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
 
LVL 1

Author Comment

by:ico2
ID: 10775436
wahay i downloaded the second one and it works great.
thanks so much!!!!
0
 
LVL 14

Expert Comment

by:wayside
ID: 10775806
Isn't Turbo C a 16 bit compiler?
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10775876
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
 
LVL 1

Author Comment

by:ico2
ID: 10776440
since a previous incident which i don't want to speak about i avoid using anything with linux in the title.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now