You are not logged in.

#1 2012-04-20 06:11:23

chris-kun
Member
From: SF Bay Area
Registered: 2010-09-07
Posts: 235
Website

Can't get scons to link correctly

Hey guys, anyone feel like helping out a C nub? tongue. I'm trying to get scons to link libonion correctly and I can't seem to figure out how to do this. Here's my code: https://github.com/saiko-chriskun/audiakon

Been sitting here for hours now heh. Any insight would be greatly appreciated!


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you." -- Bregol

Offline

#2 2012-04-20 10:53:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Can't get scons to link correctly

It would help to know what you have attempted and what error messeges you are getting.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2012-04-20 13:17:03

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: Can't get scons to link correctly

I've no clue of scons at all, so I might be mistaken, but I didn't find any kind of linking instruction in your build files.  To me it looks like you are somehow assuming that the "Repository()" method would magically build libonion and link it into your program.  How did you get this idea?! The documentation of "Repository()" doesn't even mention the term "linking". Actually, this method doesn't have anything to do, it apparently merely specifies additional directories to search for source or header files.

There is however a dedicated section about Linking with libraries. Basically, you need to specify the names of libraries to link against in the "Program()" call.  In order to do so, you need to manually build libonion before.

Offline

#4 2012-04-20 17:12:50

chris-kun
Member
From: SF Bay Area
Registered: 2010-09-07
Posts: 235
Website

Re: Can't get scons to link correctly

@Trilby- just run 'scons'. It'll also output the standard gcc command it's trying to use to build it.

@lunar- Yeah I've read all the scons docs. idk is there something obvious I'm just not seeing? The libonion docs just seems to #include the header files, though (as seen here). I've simply copied that into my main.c.

EDIT: @lunar- I /can/ actually get it to build/link individual onion source files, but I would have to do that manually for every file and that just seems like the wrong way to go about things.

EDIT2: idk if it helps but it DOES find and compile the header files properly, it just doesn't match the function prototypes to their definitions.

Last edited by chris-kun (2012-04-20 17:23:55)


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you." -- Bregol

Offline

#5 2012-04-20 17:31:43

Oxyd
Member
From: Czech Republic
Registered: 2008-01-17
Posts: 167

Re: Can't get scons to link correctly

[starlight] /tmp/audiakon > scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o build/main.o -c -Ibuild -Isrc -Isubmodules/onion/src -Isubmodules/onion/build src/main.c
src/main.c:3:25: fatal error: onion/onion.h: No such file or directory
[starlight] /tmp/audiakon > ls submodules/onion 
[starlight] /tmp/audiakon > 

Looks like you simply don't have any onion/onion.h file in your repository. That would indeed be a problem.

But this isn't a linking problem, but rather a compiling one. Am I getting the same error as you are?

Offline

#6 2012-04-20 17:34:25

chris-kun
Member
From: SF Bay Area
Registered: 2010-09-07
Posts: 235
Website

Re: Can't get scons to link correctly

run: git submodule init && git submodule update


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you." -- Bregol

Offline

#7 2012-04-20 17:45:55

Oxyd
Member
From: Czech Republic
Registered: 2008-01-17
Posts: 167

Re: Can't get scons to link correctly

Haha. Yes, sorry.

I managed to get it to build&link with the following src/SConscript:

env = Environment(
  CPPPATH = ['.'],
  LIBPATH=['../submodules/onion/src/onion'],
  LIBS=['onion_static', 'pthread', 'gnutls', 'rt', 'gcrypt']
)

Export('env')
env.Program('../bin/audiakon', Glob('*.c'))
Repository('../submodules/onion')

I'll admit I've never used the Repository SCons function, but after reading the manpage, it doesn't seem to be what you want:

              To scons, a repository is a copy of the source tree,  from  the  top-level
              directory  on  down, which may contain both source files and derived files
              that can be used to build targets in the local source tree.  The canonical
              example  would be an official source tree maintained by an integrator.  If
              the repository contains derived files, then the derived files should  have
              been built using scons, so that the repository contains the necessary sig‐
              nature information to allow scons to figure out when it is appropriate  to
              use  the  repository  copy  of  a  derived  file,  instead of building one
              locally.

Offline

#8 2012-04-20 17:50:04

chris-kun
Member
From: SF Bay Area
Registered: 2010-09-07
Posts: 235
Website

Re: Can't get scons to link correctly

hm that's weird. I copied that exact SConscript and I get:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o build/main.o -c -Ibuild -Isrc -Isubmodules/onion/src -Isubmodules/onion/build src/main.c
gcc -o bin/audiakon build/main.o -Lsubmodules/onion/src/onion -Lsubmodules/onion/submodules/onion/src/onion -lonion_static -lpthread -lgnutls -lrt -lgcrypt
ld: warning: directory not found for option '-Lsubmodules/onion/submodules/onion/src/onion'
ld: library not found for -lonion_static
collect2: ld returned 1 exit status
scons: *** [bin/audiakon] Error 1
scons: building terminated because of errors.

[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you." -- Bregol

Offline

#9 2012-04-20 17:51:16

Oxyd
Member
From: Czech Republic
Registered: 2008-01-17
Posts: 167

Re: Can't get scons to link correctly

I had to build the onion library myself before trying to build your audiakon. Since onion doesn't even use SCons, I don't think you can expect it to get built automatically with SCons. Unless you write your own SConscript for it, of course.

Offline

#10 2012-04-20 17:52:34

chris-kun
Member
From: SF Bay Area
Registered: 2010-09-07
Posts: 235
Website

Re: Can't get scons to link correctly

what's the command to get onion to build?

EDIT: ah I think I got it, "cmake -G "Unix Makefiles" tongue

Last edited by chris-kun (2012-04-20 18:06:48)


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you." -- Bregol

Offline

#11 2012-04-20 17:53:12

Oxyd
Member
From: Czech Republic
Registered: 2008-01-17
Posts: 167

Re: Can't get scons to link correctly

cd submodules/onion && cmake . && make

Last edited by Oxyd (2012-04-20 17:53:21)

Offline

#12 2012-04-20 18:08:00

chris-kun
Member
From: SF Bay Area
Registered: 2010-09-07
Posts: 235
Website

Re: Can't get scons to link correctly

hmm, cmake seemed to work fine, but when executing make:

Scanning dependencies of target onion
[  1%] Building C object src/onion/CMakeFiles/onion.dir/onion.c.o
/Users/chris/code/audiakon/submodules/onion/src/onion/onion.c:151:20: error: malloc.h: No such file or directory
make[2]: *** [src/onion/CMakeFiles/onion.dir/onion.c.o] Error 1
make[1]: *** [src/onion/CMakeFiles/onion.dir/all] Error 2
make: *** [all] Error 2

[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you." -- Bregol

Offline

#13 2012-04-20 18:15:35

Oxyd
Member
From: Czech Republic
Registered: 2008-01-17
Posts: 167

Re: Can't get scons to link correctly

Wow. /usr/include/malloc.h comes with the glibc package which is in the base group. In other words, you should have it in your system. Try running make VERBOSE=1 -- it should output the commands it runs. Perhaps it's doing something weird?

Offline

#14 2012-04-20 18:16:33

chris-kun
Member
From: SF Bay Area
Registered: 2010-09-07
Posts: 235
Website

Re: Can't get scons to link correctly

hm yeah it might be a mac thing. My arch machine is back home but I'm actually at work right now so I was building on my mac hehe. Lemme ssh into my machine and see if it works there.


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you." -- Bregol

Offline

#15 2012-04-20 18:18:00

Oxyd
Member
From: Czech Republic
Registered: 2008-01-17
Posts: 167

Re: Can't get scons to link correctly

That might well be it. You're going to have all necessary development packages installed on your Mac so that you have the headers and the libraries you want to use. (Starting with the C standard headers.) As I'm not a Mac user, I won't help you much in what exactly those are. smile

Offline

#16 2012-04-20 18:22:17

chris-kun
Member
From: SF Bay Area
Registered: 2010-09-07
Posts: 235
Website

Re: Can't get scons to link correctly

built successfully on arch smile. also got scons to work with:

env = Environment(CPPPATH = ['.', '../submodules/onion/src'], LIBPATH = ['../submodules/onion/src/onion'], LIBS = ['onion_static', 'pthread', 'gnutls', 'rt', 'gcrypt'])
Export('env')
env.Program('../bin/audiakon', Glob('*.c'))

Thanks a bunch for the help oxyd!


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you." -- Bregol

Offline

#17 2012-04-21 11:30:52

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: Can't get scons to link correctly

@chris-kun: You'll need XCode to build on OS X.  Btw, I'd consider linking really essential knowledge when working with C, and I still don't think that you really understood why you can successfully link against libonion now.  In this case, I'd recommend you to leave Scons aside.  Don't use a build system for know, but try to build your program by hand to understand how compilation of C programs really work.

Offline

Board footer

Powered by FluxBB