5 Replies Latest reply: Mar 8, 2012 12:25 PM by 852321 RSS

    problems with make/gcc on Solaris

    852321
      I'm working on building a binary on several different platforms, but the only one giving me trouble is Solaris 10 (64-bit -- though apparently this is building a 32-bit binary). The binary relies on the following project:

      https://projects.coin-or.org/Cbc


      I can checkout their code from SVN and build it without a problem. However, we then have a small cpp file that links to those libraries. I cannot get this cpp file to build. In fact, Solaris chokes on the makefile itself complaining that one of the lines ends with the '$' (which it does). The strange thing is, this makefile works correctly on Linux. It also works just fine on Windows in the MinGW environment (I do have to add a few flags on Windows but they are completely unrelated and the line ending with '$' still still present and works).

      Since the makefile failed, I tried to run the 2 commands that it does manually. The first one succeeds but the second command fails to locate the dynamic libraries -- even though the directory they reside in is specified in the -L argument. What gives??

      I put /usr/ccs/bin and /usr/sfw/bin in my PATH variable so that I can use make and gcc. I had to add /usr/sfw/lib to the LIBDIR variable, otherwise I was getting even more errors. Here is the makefile and the error that I get when I try to run make:

      -----
      -bash-3.2$ cat makefile
      CPP = gcc
      COINPATH = /export/home/locuser/cbc_source/coin-cbc
      CPATH += -I$(COINPATH)/include/coin
      LIBDIR = -L$(COINPATH)/lib:/usr/sfw/lib
      COINLIBS = -lCbcSolver -lCbc -lCgl -lOsiClp -lClp -lOsi -lCoinUtils -lm
      CFLAGS += -DUSE_SNAPSHOT=1 -DNEW_SIMULATOR=1 -g $(CPATH)
      DATASTORE=$(PSASRC)/datastore.a

      .c.o:
      $(CC) $(CFLAGS) -c -o $@ $<

      .cpp.o:
      $(CPP) $(CFLAGS) -c -o $@ $<

      OBJSx = cbc.o

      cbc: $(OBJSx) $
      $(CPP) $(CFLAGS) -o cbc $+ $(LIBDIR) $(COINLIBS)
      -bash-3.2$ make
      mksh: Fatal error in reader: '$' at end of line
      Current working directory /export/home/locuser/cbc_source/solver
      -----



      Then this is what happened when I tried to run the 2 commands manually:


      -----
      -bash-3.2$ gcc -DUSE_SNAPSHOT=1 -DNEW_SIMULATOR=1 -g -I/export/home/locuser/cbc_source/coin-cbc/include/coin -c -o cbc.o cbc.cpp
      -bash-3.2$ gcc -DUSE_SNAPSHOT=1 -DNEW_SIMULATOR=1 -g -I/export/home/locuser/cbc_source/coin-cbc/include/coin -o cbc cbc.o -L/export/home/locuser/cbc_source/coin-cbc/lib:/usr/sfw/lib -lCbcSolver -lCbc -lCgl -lOsiClp -lClp -lOsi -lCoinUtils -lm
      ld: fatal: library -lCbcSolver: not found
      ld: fatal: library -lCbc: not found
      ld: fatal: library -lCgl: not found
      ld: fatal: library -lOsiClp: not found
      ld: fatal: library -lClp: not found
      ld: fatal: library -lOsi: not found
      ld: fatal: library -lCoinUtils: not found
      ld: fatal: file processing errors. No output written to cbc
      collect2: ld returned 1 exit status
      -----

      However, if I cd into the directory /export/home/locuser/cbc_source/coin-cbc/lib then the libraries do indeed exist there:

      -----
      -bash-3.2$ cd /export/home/locuser/cbc_source/coin-cbc/lib
      -bash-3.2$ ls lib*.so.0
      libCbc.so.0 libClp.so.0 libOsiCbc.so.0
      libCbcSolver.so.0 libCoinUtils.so.0 libOsiClp.so.0
      libCgl.so.0 libOsi.so.0 libOsiCommonTests.so.0
      -----




      Any ideas on what I am doing wrong here? It seems like there is something non-standard about make on Solaris?
        • 1. Re: problems with make/gcc on Solaris
          User171873
          Given that it compiles properly under Linux, you might want to try using "gmake" instead of "make". This is the GNU make which is compatible with the make used on Linux. If you don't have it installed, you may add the SUNWgmake package.
          • 2. Re: problems with make/gcc on Solaris
            852321
            Thanks. I did not realize that Solaris had its own make command and then a separate gnu make called gmake. I just assumed that make was gnu make. So using that instead helps get past the first issue with the '$' character at the end of the line. However, the linker is still unable to locate the libraries even though are located in the directory specified in -L (as shown in my first post). For grins I thought maybe they existed but weren't readable so I checked their permissions. They are owned by my user and are all 755, so this is not an issue.

            Any ideas what to try now? It doesn't complain about libm so it seems to be finding it in /usr/lib (which I know it searches by default). I'm not sure why it cannot find the shared libraries in /export/home/locuser/cbc_source/coin-cbc/lib because I pass that directory in to the -L argument...it should work.




            -bash-3.2$ gmake
            gcc -DUSE_SNAPSHOT=1 -DNEW_SIMULATOR=1 -g -I/export/home/locuser/cbc_source/coin-cbc/include/coin -c -o cbc.o cbc.cpp
            gcc -DUSE_SNAPSHOT=1 -DNEW_SIMULATOR=1 -g -I/export/home/locuser/cbc_source/coin-cbc/include/coin -o cbc cbc.o -L/export/home/locuser/cbc_source/coin-cbc/lib:/usr/sfw/lib -lCbcSolver -lCbc -lCgl -lOsiClp -lClp -lOsi -lCoinUtils -lm
            ld: fatal: library -lCbcSolver: not found
            ld: fatal: library -lCbc: not found
            ld: fatal: library -lCgl: not found
            ld: fatal: library -lOsiClp: not found
            ld: fatal: library -lClp: not found
            ld: fatal: library -lOsi: not found
            ld: fatal: library -lCoinUtils: not found
            ld: fatal: file processing errors. No output written to cbc
            collect2: ld returned 1 exit status
            gmake: *** [cbc] Error 1
            • 3. Re: problems with make/gcc on Solaris
              Catch 22
              Perhaps displaying the processing of files and libraries when handling libraries can help:

              http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

              3.3.2. LD_DEBUG

              export LD_DEBUG=files
              • 4. Re: problems with make/gcc on Solaris
                800381
                Try replacing

                LIBDIR = -L$(COINPATH)/lib:/usr/sfw/lib

                with

                LIBDIR = -L$(COINPATH)/lib -L/usr/sfw/lib
                • 5. Re: problems with make/gcc on Solaris
                  852321
                  Woo hoo! I was able to finally get past this. Thank you both for you assistance. I tried the LD_DEBUG=files option and it didn't seem to help me much. I got some additional output but it appeared unrelated. So then I separated out my -L argument into 2 separate arguments. This changed the error messages and led to some errors about operator new and delete not being found as well as some gz and BZ2 functions not being found:

                  -----
                  Undefined first referenced
                  symbol in file
                  operator new[](unsigned int) cbc.o (symbol belongs to implicit dependency /usr/sfw/lib/libstdc++.so.6)
                  operator new(unsigned int) cbc.o (symbol belongs to implicit dependency /usr/sfw/lib/libstdc++.so.6)
                  std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) constcbc.o (symbol belongs to implicit dependency /usr/sfw/lib/libstdc++.so.6)
                  std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))cbc.o (symbol belongs to implicit dependency /usr/sfw/lib/libstdc++.so.6)
                  vtable for __cxxabiv1::__si_class_type_infocbc.o (symbol belongs to implicit dependency /usr/sfw/lib/libstdc++.so.6)
                  std::basic_ostream<char, std::char_traits<char> >::operator<<(int)cbc.o (symbol belongs to implicit dependency /usr/sfw/lib/libstdc++.so.6)
                  BZ2_bzRead /export/home/locuser/cbc_source/coin-cbc/lib/libCoinUtils.so
                  operator delete[](void*) cbc.o (symbol belongs to implicit dependency /usr/sfw/lib/libstdc++.so.6)
                  operator delete(void*) cbc.o (symbol belongs to implicit dependency /usr/sfw/lib/libstdc++.so.6)
                  gzopen /export/home/locuser/cbc_source/coin-cbc/lib/libCoinUtils.so
                  gzread /export/home/locuser/cbc_source/coin-cbc/lib/libCoinUtils.so
                  BZ2_bzReadOpen /export/home/locuser/cbc_source/coin-cbc/lib/libCoinUtils.so
                  BZ2_bzWriteOpen /export/home/locuser/cbc_source/coin-cbc/lib/libCoinUtils.so
                  ...
                  -----



                  This led me to two conclusions:

                  1. I needed to change the makefile to use g++ instead of gcc (due to the messages about the operators existing in libstd*c++*.so.6).
                  2. I needed to include the libz and libbz2 libraries (by adding -lz and -lbz2) to COINLIBS.


                  I made those 2 changes to the makefile and it built successfully with gmake! So now I'm off to go document this information on our wiki. Thanks for the suggestions -- they pointed me in the right direction and ultimately helped me resolve this issue. :)