Avatar of lwdalton3
lwdalton3Flag for United States of America

asked on 

How to link cstdlib from command line in Linux

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
C++

Avatar of undefined
Last Comment
jkr
Avatar of jkr
jkr
Flag of Germany image

What errors are you getting?
Avatar of lwdalton3
lwdalton3
Flag of United States of America image

ASKER

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

Avatar of jkr
jkr
Flag of Germany image

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

#include <string.h>
Avatar of lwdalton3
lwdalton3
Flag of United States of America image

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of lwdalton3
lwdalton3
Flag of United States of America image

ASKER

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



Avatar of lwdalton3
lwdalton3
Flag of United States of America image

ASKER

And if push comes to shove I can write my own strcat function-- within my limited programming abilities but would rather not.
Avatar of lwdalton3
lwdalton3
Flag of United States of America image

ASKER

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
Avatar of jkr
jkr
Flag of Germany image

Good to hear that it worked ;o)
C++
C++

C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.

58K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo