Scons: shared library for each source file - scons

I'm having sconscript that has a line like this:
EXT_SHADERS = shader_env.SharedLibrary('scrubs', source_files, LIBPREFIX='')
And the source_files is "abbreviated" from:
src_base_dir = os.path.join(shader_env['ROOT_DIR'], 'contrib', 'extensions', 'scrubs', 'shaders')
source_files = [os.path.join('shaders', x) for x in find_files_recursive(src_base_dir, ['.c', '.cpp'])]
Now I know from the docs this builds one shared library named scrubs but what need is for each .cpp file in source folder one shared library built only from it's corresponding source file (.cpp) and option to add more sources later without changing the build script, is anything like this possible cause.I'm not seeing anything in the docs or elsewhere,
Thanks in advance

If you want one shared library per source file and that the library name has the same base-name as the source file (fileName1.cc => libfileName1.so, fileName2.cc => libfileName2.so) then you'll have to write some more python code, preferably using the os.path.splitext() function.
Here is an example.
Also, from your answer, I see the possibility that the source files are not in the same directory structure as the root SConsctruct, which is not supported by SCons. Here are two examples (one supported, the other not)
Supported dir structure
topDir/
SConstruct
srcDir/
srcFile1.cc
srcFile2.cc
Not supported dir structure
topDir/
subDir1/
SConstruct
subDir2/
srcFile1.cc
srcFile2.cc

Related

How to get stack build/install to include resource files (configs, images etc.)

After having picked up stack as a step in starting to write non-trivial haskell programs (larger than a single file) I've run across the problem of not knowing how to get stack to recognize .ini files and such. It doesn't seem to fit anywhere in the .cabal or stack.yaml files.
For clarification: after running stack build/install, the folder with the generated .exe doesn't have the resources, and so of course the program crashes with a bunch of IO errors (file not found).
There are two options. The one I assume you're looking for is data files. To do this, you'll essentially:
Add the relevant files to the data-files field in your .cabal file so that they are installed when building your package
Add the Paths_package_name module to your other-modules in your .cabal file (replace package_name with your package name)
Import that Paths_* module where needed
Use the generated getDataFileName :: FilePath -> IO FilePath function to get the absolute path to the data file you need
The alternative is to embed the data file contents inside the executable itself using Template Haskell, such as with the file-embed package.

How to add .so file in tizen

I'm new to tizen platform. I have a .so file. Is it possible to use .so file's in tizen native, web or hybrid app? If yes, can you please guide me how to use, it would be helpful for me to complete my task.
After research so much of time, I found solution
If we want to use .so file in Tizen, then you have to compile source code with an appropriate hardware architecture. You can add .so file directly to your main project.
Lets assume you have two applications:
TestLibrary (shared library)
TestApplication (which wants to use a .so file)
Procedure:
Copy the header files of shared library (in the example : TestLibrary/inc)to TestApplication's inc folder.
keep the .so file (in our example: liborg.example.testlibrary.so) in TestApplication's lib folder
Show library path as following:
a. Open TestApplication's properties window
b. C/C++ Build -> Settings
c. C++ Linker -> Libraries
d. In "Libraries(-l)" section click add and put the .so file's name excluding .so and lib (in my example: org.example.testlibrary)
Now use the .so files' functions by including the header files in your TestApplication.
for 1. I would suggest to add usr/include dir and add it to compiler path,
you'll find an example at:
https://wiki.iotivity.org/tizen

How to prevent scons from cleaning parent and sibling directories?

I'm working on implementing a build system using scons for a somewhat large software project. There is a directory structure which separates the code for individual libraries and programs into their own directories. With our existing make system, I can do a "make clean" in a single program directory and it will only clean the files associated with the source in that directory. If I do an "scons -c" though, it recognizes that the program depends on a slew of libraries that are in sibling (or cousin) directories and cleans all of the files for those as well. This is not what I want since I then have to rebuild all of these libraries which can take several minutes.
I have tried playing with the "NoClean()" command, but have not gotten it to work in the way I need. Given the size of the code base and complexity of the directory structure, I can't realistically have a NoClean() line for every file in every library.
Is there any way to tell scons to ignore any dependencies above the current directory when doing a clean (i.e. scons -c) ?
I'd love to have a good answer to this myself.
The only solution that I can offer for now is that you get Noclean working.
So in your library, you should have something like this
lib_objs = SharedObject(source_list)
mylib = SharedLibrary('libname', lib_objs)
So for this we want to protect the library and the sources from being cleaned.
NoClean([mylib, lib_objs])
Notice that I had to split the building of the object files from the library because I want to be able to pass them to NoClean as well.
Try using the target name when cleaning.
scons -c aTargetName
You can use the SCons Alias() function to simplify the target name and to also group several target names into one alias.
With this approach you'll have to add an alias in each appropriate subdir, which isn't necessarily a bad thing :)

How to generate object files in variant directory in scons

I am using scons with python 2.7.1
my question is , i want to generate the object files in build directory.
but object files are creating in my source directory.
my code is:
env.Library('Liba', Glob(builddir + '/*.c'))
can you tell me how to generate the object file inbuild directory
thanks.
In SCons terminology, what you are asking is called a variant directory, or simply VariantDir. You have a few options for placing the targets in a VariantDir, as explained here.
You could use the VariantDir() function which has the following syntax:
VariantDir(variant_dir, src_dir, [duplicate])
The duplicate argument is a boolean, which indicates if you want the source code copied to the variant dir or not.
Another way to use a VariantDir is if you have a hierarchy of SConstruct and SConscript script files, when calling the subsidiary SConscripts with the SConscript() function, one of the arguments is the variant_dir, as detailed here:
SConscript(dirs=subdirs, [name=script, exports, variant_dir, duplicate])
Notice the SConscript() function also has the duplicate argument.

C++ Creating a standalone library in linux and using it in another program

I'm trying to create a shared library for Linux such that:
other programs can use its functions and its objects
the code is not visible to final user
What i did is create a shared library with Eclipse. This library uses pthreads.
I generated .so and .lib. The .lib is in LIBRARY/Lib while the .so is in LIBRARY/Release.
Then i created another project which should use this library and i gave the path of the .lib file and the path of the .h file which only contains the inclusions of all the necessary .h of the library.
All seems working but when i run the program it crashes. When debugging it I receive the following message:
Can't find a source file at "pthread_mutex_lock.c"
Locate the file or edit the source lookup path to include its location.
What's wrong? Can someone help me please?
EDIT: I changed nothing and now I have a different error, some lines before the previous:
Can't find a source file at "random.c"
Locate the file or edit the source lookup path to include its location.
other programs can use its functions and its objects
the code is not visible to final user
These two goals directly contradict each other, and achieving both at the same time is impossible on Linux.
If some program can use your library, then I can write a new program that can do so as well.

Resources