How to get SCons StaticLibrary store the library file in another folder - static-libraries

I'm using scons for a build project. I want to make a static library from object files that reside a different directory and surprisingly I'm not able to do that. Here is a snippet of the code I'm using:
OBJECT_FILES = env.Object('main.o', 'main.cpp')
env.StaticLibrary("../mylib", OBJECT_FILES)
StaticLibrary doesn't work if I put any directory above this directory even if I use absolute path. For the current directory or any other directory under the current directory, this works with no issues.

Here's how I'd do that..
env.StaticLibrary("../${LIBPREFIX}mylib${LIBSUFFIX}", 'main.cpp')
No need to explicitly request env.Object() SCons will figure out the correct thing to do here. Unless for some reason you want to later do something with that list of Object()'s.
When you specify
env.StaticLibrary("mylib", ['main.cpp'])
SCons will automatically prepend $LIBPREFIX and append $LIBSUFFIX to mylib and on a POSIX system you'd end up with libmylib.a on Windows you'd end up with mylib.lib
Please consider joining the SCons discord server for more "live" help and discussions.

Related

Workaround for an API not allowing require a specific library (luasocket) and not able to include it via moving DLL

I am using an API called Piepan, which allows me to write Lua scripts for Mumble bots. For context, it is written in Golang using an alternative mumble implementation called Gumble. Piepan scripts are executed via cmd prompt through a piepan.exe.
I can require most libraries, like inspect.lua, and I can easily require luasocket in non-piepan scripts (scripts executed via lua.exe), but if I try to require luasocket (or what I really want, a redis library that depends on luasocket), I get an error. This is less of an error and more of a missing feature from the API, which the creator acknowledges. The creator suggests to someone else with this problem that they simply use Gumble, but I cannot do that as I am only a Lua programmer.
Here's the code of me just trying to require luasocket:
local socket = require ("include-test.socket")
(I've also tried include-test.socket.core and just socket.core)
In accordance with this stackoverflow answer, I moved my files to resemble the user's own directory, so it looks like this:
Piepan folder
-piepan exe and dlls (not luasocket dlls)
-include-test (folder)
--Script for piepan
--socket.lua
--socket folder
---core.dll
Despite the directory looking how I imagine it should based on other users' Q/As, I get this error:
.\include-test\socket.lua:13: module socket.core not found:
no field package.preload['socket.core']
Lstat : The system cannot find the path specified.
GetFileAttributesEx .\socket\core.lua: The system cannot find the path specified.
GetFileAttributesEx C:\Users\Michael\piepan\lua\socket\core.lua: The system cannot find the path specified.
GetFileAttributesEx C:\Users\Michael\piepan\lua\socket\core\init.lua: The system cannot find the path specified.
GetFileAttributesEx C:\Program Files (x86)\Lua\5.1\lua\socket\core.luac: The system cannot find the path specified.,
I've also tried including the following line, inspired by this stackoverflow answer.
package.cpath = package.cpath .. ';include-test/?.dll'
to no avail.
I am looking for any available solution, whether that be moving around dlls or compiling the original Piepan w/ extra files as needed.
(To clarify, I need a workaround that allows me to require the redis library within the same script I run through piepan. Using an outside script with the redis library to then, say, launch piepan and do something there, is not helpful to me.)

Images Disappear in Running Status on Qt

Original design :
Setting in property :
When the program is running :
All the image inside the project folder "QuickRecorder/Images/MainWindow".
How to solve this problem?
Thank you for your help.
In cases like this the reason almost always is: You use relative path to the image, and the working directory is different when you run the application, and image is not found by the relative path.
To debug, add this to your main to print current working directory:
qDebug() << QDir::currentPath();
A few solutions:
Use absolute paths (preferably so that you construct them at runtime, for example using QCoreApplication::applicationDirPath(), instead of hard-coding).
Put images to Qt resources, so they are embedded to the executable.
Change working directory after application starts (might have unintended consequences if you for example launch child processes, or with file open/save dialogs).
Untested, moved from comment to answer: To automatically copy files from the source dir to the build dir, you could add a build step "Custom Process Step" in the Qt Creator project settings. The command you might want to use for the case of this question might be (again, untested):
cp -rv %{sourceDir}/QuickRecorder %{buildDir}

[ Bison ]Is it possible to customize runtime data dir or specify a relatif path in config of compilation?

I am doing the build local of Bison(Linux), to provide it to other team to use.
I need to download its source from homepage and build it local, then install etc... but problem is that, after we build it(its lib/bin ..), the user of it need to use it at other pc(rather than the same host than us).
I notice that, at the build/install for Bison, we need to specify the path like datarootdir etc for the .configure, which provides an absolute path into the build and which used later in runtime for binary of Bison. (dir inside 'Share' for instance).
But since this path in build we specified would be different from the people(user)'s host's real dir. (the lib/bin are rsync later to other ppl's pc) Then this path of my local would not work for them.
My question is that, is it possible to specify a relatif path while compile/install Bison,(for example relatif to Bison binary etc). Or while using the binary of Bison, is it possible to customize the datadir etc for it?
So this could be more flexible at the user side later? if else we have to provide the same dir structure exact the runtime onw as the built one.
Thanks folks!
You can override the data path with the following:
BISON_PKGDATADIR=/some/other/path/share/bison

appledoc Exception: at least one directory

After wasting some time to figure out what goes wrong, I finally have to ask for help. I want to use appledocs from Gentle Bytes. I followed every step of the quick install guide, but I´m not able to compile the project.
Here is what I´ve done:
1. cloned it from git://github.com/tomaz/appledoc.git
2. installed the templates to ~/Library/Application Support/appledoc
3. tried to compile the project
Everytime I try to compile, I get following error:
ERROR: AppledocException: At least one directory or file name path is required, use 'appledoc --help'
What do I have to do now?
Sounds like you've compiled it just fine and are now running the program. If it's a command-line program try command-option-R in Xcode to provide some arguments (i.e. names of files that you want to process).
The error means you didn't give it source paths: after all switches, you must give it at least one path to your source files. Can be either file or directory. In later case it will recursively scan the dir. Here's example
appledoc <options> ~/MyProject
Above example will use ~/MyProject directory as a source. You can also add multiple source paths. Note that you need to give the tool few options, see this page for minimum command line and other usage examples.
You either have to copy appledoc executable to one of directories in your path, as suggested by Caleb, or use full path to it when invoking (for example: /path/to/appledoc)

Cross-compile with relative pathnames - for binary portability/embeddability? (GCC)

Say I am creating an application bundle with some scripts, maybe a daemon, or even a helper binary... When compiling such a binary.. is it feasible to ./configure/make it with only relative paths? For example, a more conscientious Makefile will include for provisions such as...
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/hiawatha]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]
This is great, you can install everything to /opt/local instead of /usr/local. Maybe even go crazy, and rename the binaries via sed.. I get it..
But what remains unclear in my tiny brain, is if the ability to arbitrarily set paths in such a manner extends to the ability to map the directories relative to the executable, in a manner similar to...
--prefix=PREFIX install architecture-independent files in PREFIX [/usr/local]
--prefix=./ aka [../relative/to/binary]
So, for example, no matter where you launched the bin from, it would always know that it's .conf file was going to be up one folder, in the that relative ../etc folder, or possibly even right next to it, in the same directory, ./. Similarly, you could guarantee write access to log and pid files, etc, without wondering about your target's permissions/directory structure...
This would enable a completely portable /bin /etc /lib /var directory structure, within a PATH to which I can guarantee some semblance of predictability... but I don't think it just "works" like that.. And I am unsure if simply "linking statically" or otherwise ? truly creates binaries that are able to be moved to another system (albeit, for this scenario, to ones with the same support libs in the same places, so as not to muddle the issue) Is it possibly to cross-compile in this manner? And can you build for multiple architectures in the same build cycle? (For example i386 AND x86_64 at the same time)
Maybe I could just use a recommendation of a good GNU/GCC primer ( CC, CFLAGS, LDFLAGS, -l, , -I , and CPP 101, etc.) but that wasn't written for (and by) Math teachers - in the 70's?
In full generality, no, that won't work. There are things in /etc for example that are expected to be shared by the whole system and won't work correctly if you're trying to keep a private copy for one app.
With that said, your app probably isn't using every single shared resource on the system. Either using a local /bin and /sbin, or symlinking to the real ones from a relative path within your app's directory should be fine. /var seems less likely as something that your app needs to know about directly - anything stopping you from storing logs your own way, or using syslogd?

Resources