Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to compile several third-party software from source code (i.e. zchaff, argosat) and get errors such as:

Error: ‘strlen’ was not declared in this scope
Error: ‘strcmp’ was not declared in this scope

Here's the full error message text (also on Ubuntu Pastebin):

erelsgl@erel-biu:~/Dropbox/theorem-prover/argosat-1.0$ make
make  all-recursive
make[1]: Entering directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0'
Making all in src
make[2]: Entering directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0/src'
Making all in strategies
make[3]: Entering directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0/src/strategies'
/bin/bash ../../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I../.. -I../../src -I../../src/auxiliary -I../../src/basic-types   -ffloat-store -Wall -Woverloaded-virtual -ansi -pedantic -Wno-strict-aliasing -DNDEBUG -O3 -MT libstrategies_la-RestartStrategy.lo -MD -MP -MF .deps/libstrategies_la-RestartStrategy.Tpo -c -o libstrategies_la-RestartStrategy.lo `test -f 'RestartStrategy.cpp' || echo './'`RestartStrategy.cpp
 g++ -DHAVE_CONFIG_H -I. -I../.. -I../../src -I../../src/auxiliary -I../../src/basic-types -ffloat-store -Wall -Woverloaded-virtual -ansi -pedantic -Wno-strict-aliasing -DNDEBUG -O3 -MT libstrategies_la-RestartStrategy.lo -MD -MP -MF .deps/libstrategies_la-RestartStrategy.Tpo -c RestartStrategy.cpp -o libstrategies_la-RestartStrategy.o
In file included from ../../src/SolverListener.hpp:22:0,
                 from RestartStrategyConflictCounting.hpp:24,
                 from RestartStrategyMinisat.hpp:22,
                 from RestartStrategy.cpp:22:
../../src/basic-types/Literal.hpp: In static member function ‘static void ArgoSat::Literals::shuffleVector(std::vector<unsigned int>&)’:
../../src/basic-types/Literal.hpp:83:23: error: ‘rand’ was not declared in this scope
RestartStrategy.cpp: In static member function ‘static ArgoSat::RestartStrategy* ArgoSat::RestartStrategy::createFromCmdLine(ArgoSat::Solver&, int, char**, int)’:
RestartStrategy.cpp:33:40: error: ‘strcmp’ was not declared in this scope
RestartStrategy.cpp:35:37: error: ‘strcmp’ was not declared in this scope
RestartStrategy.cpp:37:37: error: ‘strcmp’ was not declared in this scope
RestartStrategy.cpp:39:34: error: ‘strcmp’ was not declared in this scope
RestartStrategy.cpp:41:36: error: ‘strcmp’ was not declared in this scope
RestartStrategy.cpp:43:41: error: ‘strcmp’ was not declared in this scope
make[3]: *** [libstrategies_la-RestartStrategy.lo] Error 1
make[3]: Leaving directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0/src/strategies'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/erelsgl/Dropbox/theorem-prover/argosat-1.0'
make: *** [all] Error 2
erelsgl@erel-biu:~/Dropbox/theorem-prover/argosat-1.0$

I found in other questions, such as http://stackoverflow.com/questions/4564850/strlen-was-not-declared-in-this-scope-c, that these errors can be solved by inserting "include" statements into the source code.

But, I downloaded the source code from other sites and I am pretty sure it works for them as is. So, why doesn't it work for me?

(I have Ubuntu 12.04.4, g++ 4.6.3)

share|improve this question
1  
Just check if #include<string.h> statement is included in each .c file if not then add the statement –  Null pointer Jan 19 at 10:07
    
@EliahKagan Thanks! I didn't know about paste.ubuntu.com. I now put the entire message log over there. –  Erel Segal Halevi Jan 19 at 11:28
    
@ErelSegalHalevi Based on the information you've provided, my answer explains this ...but for an explicit solution, you'll have to also tell us exactly what you downloaded and everything you did with it up to the point when you ran make. (You provided a link to argo.matf.bg.ac.rs/?content=downloads which I presume is the program in question but more detailed information would be helpful, as it's not totally clear what you downloaded there or if there were steps run before make.) –  Eliah Kagan Jan 19 at 11:49
add comment

1 Answer 1

up vote 1 down vote accepted

This seems to be the result of a bug in the source code for the program (at least in the specific case you provided details on). But fortunately it is one that you can work around without too much trouble!

Since this is a recurring issue and often happens when source code for a program tested on another platform (most often Windows) is brought to Ubuntu, we should probably consider this question on-topic even though it involves bugs and programming. With that said, reporting the bug to the program's developer is an appropriate action to take as well.

It appears that one of the following situations applies:

  1. On the platform(s) where the program was developed and tested, the header file(s) providing identifiers like strlen were indirectly included by being pulled in by the implementation of some other header file. This is unintentionally implementation-specific behavior.
  2. Some weird C++ standard library implementations allow a lot of things that are technically prohibited and a few things that are conceptually impossible. (This does not make them bad overall, necessarily.) I believe some versions of Microsoft's C++ library give you functions like strlen as global identifiers even from C++-style #includes like #include <cstring>. This will not work with GCC/g++ on Ubuntu.

In either case, you will probably have to edit the source code slightly, as Null pointer suggested. Since this is quite simple, we can walk you through this if you tell us exactly what files you downloaded and what steps, if any, you took before running make. You can edit your question to include this information as well.

Null pointer's advice to add something like #include <string.h> at the top of the files where the errors are happening will likely work. It may or may not be the best way to fix this. If situation 2 is what is happening, a using statement for the needed keywords (or the whole std namespace if necessary) would suffice.

share|improve this answer
    
I added an "include" statement and it solved the problem. Thanks! I also notified the package maintainers in order to help future users. –  Erel Segal Halevi Jan 19 at 15:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.