mercredi 6 juillet 2016

Determining which static libraries are linked unnecessarily


I want to cut down library dependencies on some C++ executables I'm compiling for Linux with GCC. There is a list of probably 40 static libraries that being linked. I want to determine which ones are unnecessary, and I would rather not try removing them one at a time to find out.

Is there an option in GCC to make it warn about libraries that are linked but don't resolve any symbols?

Are there any Linux tools available that will help me out?

To be clearn, I'm not concerned with unused code being linked into the executable. Rather, I'm concerned with the unnecessary build dependencies. I'd like to cut down my build times.


find string in map function c++


I've never used map lib in C++ and I'm implementing a graph adding cities on it, and this is what I'm doing:

I read a city from a txt file, then I look for it in mymap. If I find it, don't need to add in the graph and in the map, if not, I create a integer key for it,put in the map and then add in the graph.

The problem is, I don't know how to find a string in mymap, the find function works just for char,right?

mymap is

map<int,string> cities;

example cities["New York"] = 1; cities["Brazilia"] = 2;


Check for container type


How can I check for a type of container? I.e.

template <class Container1>
void func (Container1 &cont_1)
{
  if (cont_1 is list container)
    //do stuff
  if (cont_1 is vector container)    
    //do other stuff
}

The only two possibilities I have are list and vector. Note that I don't know the type of values within list/vector, i.e. vector<char> or vector<int>, etc. is possible, thus I just want to get the information of getting a vector or a list. I came across typeid and type info, but did not really get it done.


iOS background execution and password protection


In Apple Doc Understanding When Your App Gets Launched into the Background says

When password protection is enabled on the device, the system does not launch an app in the background before the user first unlocks the device.

If app is depending on region monitoring then it will not work, Users cannot keep unlocking there iPhones after every few minute that some app will wake in background.

How an region monitoring app will wake in background and do its stuff when an password protected device will not let the app launch in background?


How to check if file is appropriated with database driver in Qt


Assuming I want to open a connection to SQLite3 database in Qt. It will be connected to an existed database dbName. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); Now I need to set db.setDatabaseName(dbName), where dbName is received through a QFileDialog. However, as long as dbName is a valid file name, then db.open() is always true. Is there anyway to check if the file dbName is a SQLite3 database, but not of any other type? What I can do now is to execute a query and check for error like: db.setDatabaseName(dbName); if (db.open()) { QSqlQuery qr(db); if (!qr.exec(".database;")) { qDebug() << qr.lastError().text(); return false; } } but it won't work if the file is empty.

Variable used before being initialized in function


I'm making a ro sham bo game. Functions in swift are different than what I have used before. I keep getting an error:

Variable used before being initialized in function

What am I doing wrong?

import Foundation
import UIKit
class Result: UIViewController {
    var rval: Int?
    var chosen: Int?
    func determineWinner() -> Int {
        var returnval: Int
        if (chosen == rval){
            returnval = 2
        }
        else if (chosen == 1 && rval == 3){
            returnval = 1
        }
        else if (chosen == 1 && rval == 2){
            returnval = 0
        }
        else if (chosen == 2 && rval == 1){
            returnval = 1
        }
        return (returnval)
    }

    @IBOutlet weak var wl: UILabel!

    @IBAction func PlayAgain(sender: AnyObject) {
    }
    override func viewDidLoad() {
        print(chosen)
    }
}

Does anyone know if this is possible using AVFoundation?


I have created a slider that generates a tone. I need it to generate two tones but xcode is producing a plethora of errors any way I attempt it - is this impossible?

Here is some of the set up I'm using:

    tone = AVTonePlayerUnit()
    slider.value = 0.0
    let format = AVAudioFormat(standardFormatWithSampleRate: tone.sampleRate, channels: 1)
    print(format.sampleRate)
    engine = AVAudioEngine()
    engine.attachNode(tone)
    let mixer = engine.mainMixerNode
    engine.connect(tone, to: mixer, format: format)
    do {
        try engine.start()
    } catch let error as NSError {
        print(error)
    }

EDIT:

I have solved the problem by creating a separate class for the AVTonePlyerUnit. I have a separate problem with creating a volume slider for the generator.