How to link cstdlib from command line in Linux

lwdalton3
lwdalton3 used Ask the Experts™
on
I have bought a new computer (the last purchased in 2007 which used Fedoroa Linux. I find some reference to SDO or DSO or the like, and explicit linkage, but I cannot seem to find the "perfect command." I ran two programs one of which held all the class function. The following always ran perfectly:

g++ myprogram.cpp myprogramclasses.cpp -o myprogram.

Any suggestion-- several different options would probably be best.

I assume this Fedora 14 (Ithink is the current version) shoud have C++ in the usual default location. I did not install myself.

Thank you Les Dalton

I am stranded without being able to get started
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
jkr
Top Expert 2012

Commented:
What errors are you getting?

Author

Commented:
such as

error : 'strcpy' was not declared in this scope

my program had the following include statements

#include <iostream>

#include <cstdlib>
#include <cmath>

#include "dmtoolkit.h"

the command entered

g++ dmtoolkit_main.cpp dm_toolkit_class.cpp -o dm

The above ran perfectly in Fedora 7 on a 2007 era computer, and the programs have changed not one iota and the computers were bought from the same vendor. The above are the programs  where one holds the class functions and dmtoolkit.h is in the same directory and defines the function. And errorr were



In file included from dm_toolkit_class.cpp:3:0:
dmtoolkit.h: In member function ‘void dm_toolkit::concat_with_tab(char*, char*)’:
dmtoolkit.h:68:24: error: ‘strcat’ was not declared in this scope

In fact the whole string of errors are pasted below. And I get the same errors whether or not I am root or not as I tried being superusr in case that had something to do with it.

[root@raven 9_15_08]# g++ dmtoolkit_main.cpp dm_toolkit_class.cpp -o dm
In file included from dmtoolkit_main.cpp:5:0:
dmtoolkit.h: In member function ‘void dm_toolkit::concat_with_tab(char*, char*)’:
dmtoolkit.h:68:24: error: ‘strcat’ was not declared in this scope
dmtoolkit_main.cpp: In function ‘int main()’:
dmtoolkit_main.cpp:67:28: error: ‘strcpy’ was not declared in this scope
dmtoolkit_main.cpp:135:48: error: ‘fopen’ was not declared in this scope
dmtoolkit_main.cpp:152:32: error: ‘fgets’ was not declared in this scope
dmtoolkit_main.cpp:153:21: error: ‘strlen’ was not declared in this scope
dmtoolkit_main.cpp:166:14: error: ‘fclose’ was not declared in this scope
dmtoolkit_main.cpp:200:29: error: ‘strcat’ was not declared in this scope
dmtoolkit_main.cpp:379:17: error: ‘fputs’ was not declared in this scope
In file included from dm_toolkit_class.cpp:3:0:
dmtoolkit.h: In member function ‘void dm_toolkit::concat_with_tab(char*, char*)’:
dmtoolkit.h:68:24: error: ‘strcat’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::grab_between_mult(char*, char*, int*, int)’:
dm_toolkit_class.cpp:103:11: error: ‘strcat’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::replace_all_substr(char*, char*, char*, char*)’:
dm_toolkit_class.cpp:154:13: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp:184:16: error: ‘strcmp’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::erase_all_substr(char*, char*, char*)’:
dm_toolkit_class.cpp:219:13: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp:244:16: error: ‘strcmp’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘int dm_toolkit::find_char(char*, char)’:
dm_toolkit_class.cpp:270:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::sort_cstring_cstring(char**, int*, int)’:
dm_toolkit_class.cpp:303:34: error: ‘strcmp’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::prep_ends(char*)’:
dm_toolkit_class.cpp:332:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp:344:52: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp:351:13: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp:357:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘double dm_toolkit::string_to_double(char*)’:
dm_toolkit_class.cpp:527:21: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘int dm_toolkit::days_into(char*)’:
dm_toolkit_class.cpp:645:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘int dm_toolkit::days_in_future(char*, char*)’:
dm_toolkit_class.cpp:731:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘int dm_toolkit::year(char*)’:
dm_toolkit_class.cpp:775:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘int dm_toolkit::days_left(char*)’:
dm_toolkit_class.cpp:803:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘int dm_toolkit::find_cstring(char**, char*, int)’:
dm_toolkit_class.cpp:929:27: error: ‘strcmp’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::sort_cstring(char**, int)’:
dm_toolkit_class.cpp:970:34: error: ‘strcmp’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::dbl_to_str(char*, double, int)’:
dm_toolkit_class.cpp:1037:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp:1038:11: error: ‘strcat’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::int_to_str(char*, int)’:
dm_toolkit_class.cpp:1087:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::rev_str(char*, char*)’:
dm_toolkit_class.cpp:1107:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::grab_between(char*, char*, char, int)’:
dm_toolkit_class.cpp:1183:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::rmv_between(char*, char*, char, int)’:
dm_toolkit_class.cpp:1203:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::insert_between(char*, char*, char*, char, int)’:
dm_toolkit_class.cpp:1226:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::nums_only(char*, char*)’:
dm_toolkit_class.cpp:1262:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::add_char_pos(char*, char*, char, int)’:
dm_toolkit_class.cpp:1294:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::trade_char_pos(char*, char*, char, int)’:
dm_toolkit_class.cpp:1326:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::trade_char_pos(char*, char, int)’:
dm_toolkit_class.cpp:1354:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp:1375:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘int dm_toolkit::substring(char*, char*)’:
dm_toolkit_class.cpp:1389:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp:1411:18: error: ‘strcmp’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::rmv_last(char*, char*)’:
dm_toolkit_class.cpp:1427:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::rmv_first(char*, char*)’:
dm_toolkit_class.cpp:1447:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::rmv_first(char*)’:
dm_toolkit_class.cpp:1470:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp:1482:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::add_first(char*, char*, char)’:
dm_toolkit_class.cpp:1493:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::add_last(char*, char*, char)’:
dm_toolkit_class.cpp:1512:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::add_tab(char*)’:
dm_toolkit_class.cpp:1529:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp:1549:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘bool dm_toolkit::check_last(char*, char)’:
dm_toolkit_class.cpp:1560:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘bool dm_toolkit::check_first(char*, char)’:
dm_toolkit_class.cpp:1575:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::rmv_char_pos(char*, char*, int)’:
dm_toolkit_class.cpp:1587:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::rmv_char_pos(char*, int)’:
dm_toolkit_class.cpp:1611:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp:1631:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘bool dm_toolkit::check_char(char*, char, int)’:
dm_toolkit_class.cpp:1643:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::mid$_strip(char*, char*, int, int)’:
dm_toolkit_class.cpp:1663:21: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘int dm_toolkit::pos_char(char*, char, int)’:
dm_toolkit_class.cpp:1695:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::right$_strip(char*, char*, int)’:
dm_toolkit_class.cpp:1723:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::trade_char(char*, char*, char, char)’:
dm_toolkit_class.cpp:1749:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::trade_char(char*, char, char)’:
dm_toolkit_class.cpp:1774:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp:1792:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::rmv_char(char*, char*, char)’:
dm_toolkit_class.cpp:1803:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::left$_strip(char*, char*, int)’:
dm_toolkit_class.cpp:1824:22: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::split(char*, char*, char*, int)’:
dm_toolkit_class.cpp:1849:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::swap_strings(char*, char*)’:
dm_toolkit_class.cpp:1877:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp:1884:11: error: ‘strcpy’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘int dm_toolkit::num_char(char*, char)’:
dm_toolkit_class.cpp:1952:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::mid$(char*, char*, int, int)’:
dm_toolkit_class.cpp:1976:21: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::chars_only(char*, char*)’:
dm_toolkit_class.cpp:2000:20: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::left$(char*, char*, int)’:
dm_toolkit_class.cpp:2033:21: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::right$(char*, char*, int)’:
dm_toolkit_class.cpp:2053:21: error: ‘strlen’ was not declared in this scope
dm_toolkit_class.cpp: In member function ‘void dm_toolkit::rmv_end_spaces(char*)’:
dm_toolkit_class.cpp:2136:14: error: ‘strcpy’ was not declared in this scope

jkr
Top Expert 2012

Commented:
Well, 'strcpy()' isn't part of 'cstdlib', see http://www.cplusplus.com/reference/clibrary/cstdlib/ - for that, you'll need to

#include <string.h>
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Author

Commented:
Okay. I have inlcude and still getting the error. So now I assume I need to specifically link such as to link the math libray in C I always need -lm  but never for the string library. what is the -l? for the c i/o library which has fgets and the c library for strlen etc. I can'd pick these out after reading the gcc manual. what one gets after entering

man gcc

from the command line

ld
Top Expert 2012
Commented:
Well, first things first - these are not linker errors, but compile errors. For some reason it seems that your previous system's 'cstdlib' included everything that you'd usually need seperate header files for, i.e.

#include <stdio.h>
#include <string.h> // or '<cstring>'

Author

Commented:
We are making progress. My include files are as below-- added to both the main and class programs

#include <iostream>
#include <cstdlib>
#include <cmath>
#include "dmtoolkit.h"
#include <string.h>
#include <cstring>
#include <stdio.h>

Now my compile errors are
[root@raven 9_15_08]# g++ dmtoolkit_main.cpp dm_toolkit_class.cpp -o dm
In file included from dmtoolkit_main.cpp:5:0:
dmtoolkit.h: In member function ‘void dm_toolkit::concat_with_tab(char*, char*)’:
dmtoolkit.h:68:24: error: ‘strcat’ was not declared in this scope
In file included from dm_toolkit_class.cpp:3:0:
dmtoolkit.h: In member function ‘void dm_toolkit::concat_with_tab(char*, char*)’:
dmtoolkit.h:68:24: error: ‘strcat’ was not declared in this scope

So it seems strcat is the only problem child left. Is it likely in some other library not included?

LD



Author

Commented:
And if push comes to shove I can write my own strcat function-- within my limited programming abilities but would rather not.

Author

Commented:
The last error was mine. I had a conflict with the h file and the class program and after that all is good with a successful compile. Thanks. LD
jkr
Top Expert 2012

Commented:
Good to hear that it worked ;o)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial