We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

ico2
ico2 asked
on
Medium Priority
429 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?
Comment
Watch Question

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.

Author

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.

Commented:
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;

Author

Commented:
can't be a bad header file because i get the same error even if i include no header files.
Kent OlsenData Warehouse / Database Architect
CERTIFIED EXPERT

Commented:
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

Author

Commented:
i am just using system("c:\\command.com")
Kent OlsenData Warehouse / Database Architect
CERTIFIED EXPERT

Commented:
Hi ico2,

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


Kent
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.

Author

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.

Commented:
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.

Author

Commented:
is it possible to download the library containing this function?

Author

Commented:
will someone please tell me how to fix this problem, is there a file i can download to fix this?

Author

Commented:
or would getting a different compiler fix the problem.
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

Author

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.
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.

Author

Commented:
am i right in assuming this is a very wierd error that is not normal
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.

Author

Commented:
no it wasn't.

Author

Commented:
i am just trying that now
Possibly some of ur library files may have been corrupted.
Try copying the libraries again in the lib path.

Author

Commented:
after uninstalling my compiler and re-installing-doesn't work.

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

Author

Commented:
i am now looking for another free compiler, i will tell you if this works.

Author

Commented:
hmm i cannot find another free compiler, does anyone know of a good one?
Try CYGWIN.Its a linux simulator for windows and has gcc,the gnu c compiler.
Its free and available at www.cygwin.com

Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
wahay i downloaded the second one and it works great.
thanks so much!!!!

Commented:
Isn't Turbo C a 16 bit compiler?
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.

Author

Commented:
since a previous incident which i don't want to speak about i avoid using anything with linux in the title.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.